/
tie_matrix.pl
75 lines (56 loc) · 2.07 KB
/
tie_matrix.pl
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
use strict;
use warnings;
use SDL 2.408;
use SDLx::App; #this is in the github repo.
use SDLx::Surface::Matrix;
use SDL::Event;
use SDL::Events;
use SDL::Rect;
use SDL::Video;
my $app = SDLx::App->new(
-title => 'Application Title',
-width => 640,
-height => 480,
-depth => 32
);
load_app();
my $surface = load_surface();
my $matrix = SDLx::Surface::Matrix->new( surface => $surface );
my $event = SDL::Event->new; # create a new event
while(1) {
SDL::Events::pump_events();
while ( SDL::Events::poll_event($event) ) {
my $type = $event->type(); # get event type
exit if $type == SDL_QUIT;
}
update();
SDL::Video::update_rect( $app, 0, 0, $app->w, $app->h );
}
sub load_app {
my $mapped_color =
SDL::Video::map_RGB( $app->format(), 0, 0, 0 ); # blue
SDL::Video::fill_rect( $app, SDL::Rect->new( 0, 0, $app->w, $app->h ),
$mapped_color );
return $app;
}
sub load_surface {
my $surface =
SDL::Surface->new( SDL_ANYFORMAT, 150, 150, 32, 0, 0, 0, 0 );
my $mapped_color =
SDL::Video::map_RGB( $surface->format(), 0, 0, 255 ); # blue
SDL::Video::fill_rect( $surface,
SDL::Rect->new( 0, 0, $surface->w, $surface->h ),
$mapped_color );
return $surface;
}
sub update {
load_app();
SDL::Video::blit_surface( $surface, SDL::Rect->new( 0, 0, $surface->w, $surface->h ),
$app, SDL::Rect->new( ($app->w - $surface->w)/2 , ($app->h - $surface->h)/2, $app->w, $app->h ));
SDL::Video::lock_surface($surface);
foreach( 0 ... rand($surface->w) )
{
$matrix->[$_][rand($surface->h)] = 0xFFFFFFFF/($_+1);
}
SDL::Video::unlock_surface($surface);
}