X-Git-Url: http://git.rot13.org/?p=perl-landing-airplanes.git;a=blobdiff_plain;f=trace-path.pl;fp=trace-path.pl;h=61a40662e7590442d3ed61ddd0b7ec70177532ce;hp=5884405ee5906dc308b169e2d0af37ae4ea73f33;hb=881ba0a2bb18c36bbe3557aa89546c92a2bbaf50;hpb=45bbd5469d1dd119b8ef6e6c177b9ecc8cb5537d diff --git a/trace-path.pl b/trace-path.pl index 5884405..61a4066 100755 --- a/trace-path.pl +++ b/trace-path.pl @@ -15,6 +15,7 @@ use Data::Dump qw/dump/; my ( $w, $h ) = ( 800, 480 ); my $mouse_trashold = 10; +my $max_path_length = 200; our $app = SDL::App->new( -width => $w, @@ -34,12 +35,12 @@ our $black = SDL::Color->new( 0x00, 0x00, 0x00 ); my ( $last_x, $last_y ) = ( 0,0 ); -my $max_path_length = 100; my @path; sub curve { + return unless $#path > 4; my $curve = Math::CatmullRom->new( splice @path, 0, $#path + $#path / 2 ); - my @curve = $curve->curve( $mouse_trashold * $max_path_length ); + my @curve = $curve->curve( $mouse_trashold * $max_path_length / 2 ); warn "curve ", dump @curve; my $i = 0; @@ -61,6 +62,7 @@ sub handle_events { } elsif ( $type == SDL_MOUSEBUTTONUP() ) { warn "mouse up ", $event->button_x, ' ', $event->button_y; $mouse_down = 0; + curve; } elsif ( $type == SDL_QUIT() ) { exit; } elsif ( $type == SDL_KEYDOWN() ) { @@ -93,6 +95,7 @@ sub handle_events { $last_y = $y; } else { $mouse_down = 0; + curve; } } } else {