- Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathtestcolor.spl
67 lines (55 loc) · 1.6 KB
/
testcolor.spl
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
#!/usr/bin/env perl
#
use SDL;
use SDLx::App;
use SDL::Event;
use vars qw/ $app /;
printSTDERR<<USAGE;
Right click on any pixel to get its color values
Left click on any pixel to set its value to the last selected
USAGE
$app = SDLx::App->new( -width=> 320, -height=> 240, -depth=> 8 );
my%colors = (
red=> ( new SDL::Color-r=> 255, -g=> 0, -b=> 0 ),
green=> ( new SDL::Color-r=> 0, -g=> 255, -b=> 0 ),
blue=> ( new SDL::Color-r=> 0, -g=> 0, -b=> 255 ),
yellow=> ( new SDL::Color-r=> 255, -g=> 255, -b=> 0 ),
purple=> ( new SDL::Color-r=> 255, -g=> 0, -b=> 255 ),
white=> ( new SDL::Color-r=> 255, -g=> 255, -b=> 255 )
);
$x = 0;
$y = 0;
$rect = SDL::Rect->new(
-x=>$x,
-y=>$y,
-w=>$app->width / scalar( keys%colors ),
-h=>$app->height()
);
print"Sorted colors:\n";
for ( sortkeys%colors ) {
print"$_" . join( ",", $colors{$_}->r(), $colors{$_}->g(), $colors{$_}->b() ) . "\n";
}
for ( sortkeys%colors ) {
$rect->x($x);
$x += $rect->width();
$app->fill( $rect, $colors{$_} );
}
$app->sync();
$last = SDL::Color->new( -r=> 128, -g=> 128, -b=> 128 );
$app->sync();
$app->loop(
{ SDL_QUIT() =>sub { exit(0); },
SDL_KEYDOWN() =>sub { $app->fullscreen(); },
SDL_MOUSEBUTTONDOWN() =>sub {
my$e = shift;
if ( $e->button == 3 ) {
$last = $app->pixel( $e->button_x(), $e->button_y() );
printSTDERR"X: ", $e->button_x(), " Y: ", $e->button_y(),
" R: ", $last->r(), " G: ", $last->g(),
" B: ", $last->b(), "\n";
} else {
$app->pixel( $e->button_x(), $e->button_y(), $last );
}
},
}
);