X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;ds=sidebyside;f=trace-path.pl;h=05dccdd3694239aee03d5574069dfd883ceb05ae;hb=c65020320bcddc9ef88d6dd6604b4e28ef5a6c88;hp=ed1c2379107a22102f7a126fc7b6af69da445218;hpb=8a5f965f23705d15eb17d9eca1de3f2487868a6f;p=perl-landing-airplanes.git diff --git a/trace-path.pl b/trace-path.pl index ed1c237..05dccdd 100755 --- a/trace-path.pl +++ b/trace-path.pl @@ -9,7 +9,7 @@ use SDL::Color; use SDL::Constants; use SDL::Event; use Math::CatmullRom; -#use Algorithm::Line::Bresenham; +use Algorithm::Line::Bresenham qw(line); use Carp qw(cluck); use Data::Dump qw(dump); @@ -38,9 +38,9 @@ our $event = SDL::Event->new; our $mouse_down = 0; -our $white = SDL::Color->new( 0xff, 0xff, 0xff ); -our $red = SDL::Color->new( 0xff, 0x00, 0x00 ); -our $black = SDL::Color->new( 0x00, 0x00, 0x00 ); +our $mouse_color = SDL::Color->new( 0x00, 0x80, 0x00 ); +our $path_color = SDL::Color->new( 0xff, 0x00, 0x00 ); +our $black = SDL::Color->new( 0x00, 0x00, 0x00 ); my ( $last_x, $last_y ) = ( 0,0 ); @@ -54,10 +54,19 @@ sub curve { my $i = 0; while ( $i < $#curve ) { - my $rect = SDL::Rect->new( -x => int($curve[$i++]), -y => int($curve[$i++]), -w => 1, -h => 1 ); - $app->fill( $rect, $red ); - $app->update( $rect ); + my $from_x = int($curve[$i++]); + my $from_y = int($curve[$i++]); + my $to_x = int($curve[$i++]); + my $to_y = int($curve[$i++]); + line( + int($curve[$i++]), + int($curve[$i++]), + int($curve[$i++]), + int($curve[$i++]), + sub { $app->pixel( @_, $path_color ) } + ); } + $app->sync; } sub handle_events { @@ -102,7 +111,7 @@ sub handle_events { if ( $#path < $max_path_length ) { push @path, $x, $y; my $rect = SDL::Rect->new( -x => $event->motion_x - 1, -y => $event->motion_y -1 , -w => 3, -h => 3 ); - $app->fill( $rect, $white ); + $app->fill( $rect, $mouse_color ); $app->update( $rect ); $last_x = $x; $last_y = $y;