/test/graywin.pl

http://github.com/PerlGameDev/SDL · Perl · 50 lines · 34 code · 15 blank · 1 comment · 6 complexity · 4ecf2065f78d96a2d894398edc2a4ca5 MD5 · raw file

  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use SDL ':init';
  5. use SDL::Video ':all';
  6. use SDL::Events ':all';
  7. use SDL::Rect;
  8. use SDL::Event;
  9. use SDL::Surface;
  10. SDL::init(SDL_INIT_VIDEO);
  11. my $width = 800;
  12. my $height = 600;
  13. my $screen_surface = SDL::Video::set_video_mode( $width, $height, 32, SDL_SWSURFACE );
  14. my $event = SDL::Event->new;
  15. while (1) {
  16. while ( SDL::Events::poll_event($event) ) {
  17. exit(0) if $event->type == SDL_QUIT;
  18. if ( $event->type == SDL_MOUSEBUTTONDOWN ) {
  19. my $mapped_color = SDL::Video::map_RGB(
  20. $screen_surface->format(), rand_color(),
  21. rand_color(), rand_color()
  22. );
  23. SDL::Video::fill_rect(
  24. $screen_surface,
  25. SDL::Rect->new( $event->button_x, $event->button_y, 20, 10 ),
  26. $mapped_color
  27. );
  28. }
  29. }
  30. SDL::Video::update_rect( $screen_surface, 0, 0, $width, $height );
  31. SDL::delay(20);
  32. }
  33. sub rand_color {
  34. return int( rand(256) );
  35. }