/test/graywin.pl
Perl | 50 lines | 34 code | 15 blank | 1 comment | 6 complexity | 4ecf2065f78d96a2d894398edc2a4ca5 MD5 | raw file
1#!/usr/bin/perl 2 3use strict; 4use warnings; 5 6use SDL ':init'; 7use SDL::Video ':all'; 8use SDL::Events ':all'; 9use SDL::Rect; 10use SDL::Event; 11use SDL::Surface; 12 13SDL::init(SDL_INIT_VIDEO); 14 15my $width = 800; 16my $height = 600; 17 18my $screen_surface = SDL::Video::set_video_mode( $width, $height, 32, SDL_SWSURFACE ); 19 20my $event = SDL::Event->new; 21 22while (1) { 23 24 while ( SDL::Events::poll_event($event) ) { 25 exit(0) if $event->type == SDL_QUIT; 26 27 if ( $event->type == SDL_MOUSEBUTTONDOWN ) { 28 29 my $mapped_color = SDL::Video::map_RGB( 30 $screen_surface->format(), rand_color(), 31 rand_color(), rand_color() 32 ); 33 34 SDL::Video::fill_rect( 35 $screen_surface, 36 SDL::Rect->new( $event->button_x, $event->button_y, 20, 10 ), 37 $mapped_color 38 ); 39 40 } 41 42 } 43 44 SDL::Video::update_rect( $screen_surface, 0, 0, $width, $height ); 45 SDL::delay(20); 46} 47 48sub rand_color { 49 return int( rand(256) ); 50}