Leser: 6
![]() |
|< 1 2 3 >| | ![]() |
21 Einträge, 3 Seiten |
1
2
3
4
5
6
7
8
9
10
11
12
use Tk;
$top = new MainWindow;
$p = $top->Photo(-width => 400, -height => 300);
$c = $top->Canvas(-width => 400, -height => 300)->pack(-fill => "both", -expand => 1);
$img = $c->createImage(0,0,-image=>$p,-anchor=>"nw");
for my $x (-$p->width/2 .. $p->width/2) {
my($tx) = int($x+$p->width/2);
my $y = sin($x/10)*$p->height/2;
my($ty) = int($y+$p->height/2);
$p->put("#ff0000", -to => $tx,$ty+1,$tx+1,$ty);
}
MainLoop;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
use strict;
use Tk;
my $mw = MainWindow -> new();
my ($screenx,$screeny) = ($mw -> screenwidth(),
$mw -> screenheight());
$mw -> FullScreen(1);
$mw -> geometry("${screenx}x$screeny");
my $canvas = $mw -> Canvas (-background => "#000000",
-bd => 0,
-relief => "flat")->
pack(-fill => "both",
-expand => 1);
$mw -> bind ('<Key-q>',"exit");
MainLoop;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/perl
#Tut bei Mausbewegung einzelne Pixel färben
use strict;
use warnings;
use SDL;
use SDL::App;
use SDL::Color;
my $app = new SDL::App (
-title => 'einzelne Pixel faerbender Test',
-width => 640,
-height => 480,
-depth => 32,
);
my %actions = (
SDL_QUIT() => sub { exit(0); },
SDL_MOUSEMOTION() => \&keydown,
);
$app->loop(\%actions);
sub keydown {
my $farbe = SDL::Color->new(
-r => int(rand(255)),
-g => int(rand(255)),
-b => int(rand(255)),
);
$app->pixel(int(rand(640)), int(rand(480)), $farbe);
}
QuoteWeißt du wie man x und y position im Canvas herausfinden kann, egal wo im Skript ?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/perl -w
#
# pf.pl
#
use strict;
use Tk;
my %all;
$all{mw} = MainWindow -> new();
$all{mw} -> bind("<Key-q>","exit");
$all{canvas} = $all{mw} ->
Canvas (-background => "#000000",
-highlightthickness => 0,
-relief => "flat",
-bd => 0)->
pack(-fill => "both",
-expand => 1);
my ($screenx,$screeny) =
($all{mw} -> screenwidth(),
$all{mw} -> screenheight());
$all{photo} = $all{mw} ->
Photo (-width => $screenx,
-height => $screeny);
$all{canvas} ->
createImage (0,0,
-image => $all{photo},
-anchor => "nw");
$all{mw} -> FullScreen(1);
$all{mw} -> geometry ("${screenx}x$screeny");
for (0..$screenx) {
my $y = $_;
$y = $screeny / 2 if $y >= $screeny / 2;
point($_,$y);
for (0..10000) {}
$all{mw} -> update;
}
for (0..$screenx) {
my $y = $_;
$y = $screeny / 2 if $y >= $screeny / 2;
my $x = $screenx - $_;
point($x,$y);
for (0..10000) {}
$all{mw} -> update;
}
MainLoop;
sub point {
my ($x,$y,$color);
if ($#_ >= 0) {
$x = shift;
if ($#_ >= 0) {
$y = shift;
if ($#_ >= 0) {
$color = shift;
}
else {
$color = "#ff0000";
}
}
else {
$y = 0;
$color = "#ff0000";
}
}
else {
$x = 0;
$y = 0;
$color = "#ff0000";
}
$all{photo} ->
put ("$color",
-to => $x,$y);
}
![]() |
|< 1 2 3 >| | ![]() |
21 Einträge, 3 Seiten |