projects
/
perl-landing-airplanes.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
use Algorithm::Line::Bresenham to draw lines later
[perl-landing-airplanes.git]
/
trace-path.pl
diff --git
a/trace-path.pl
b/trace-path.pl
index
5884405
..
77a378d
100755
(executable)
--- a/
trace-path.pl
+++ b/
trace-path.pl
@@
-9,12
+9,14
@@
use SDL::Color;
use SDL::Constants;
use SDL::Event;
use Math::CatmullRom;
use SDL::Constants;
use SDL::Event;
use Math::CatmullRom;
+#use Algorithm::Line::Bresenham;
use Carp qw/confess/;
use Data::Dump qw/dump/;
my ( $w, $h ) = ( 800, 480 );
my $mouse_trashold = 10;
use Carp qw/confess/;
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,
our $app = SDL::App->new(
-width => $w,
@@
-34,12
+36,12
@@
our $black = SDL::Color->new( 0x00, 0x00, 0x00 );
my ( $last_x, $last_y ) = ( 0,0 );
my ( $last_x, $last_y ) = ( 0,0 );
-my $max_path_length = 100;
my @path;
sub curve {
my @path;
sub curve {
+ return unless $#path > 4;
my $curve = Math::CatmullRom->new( splice @path, 0, $#path + $#path / 2 );
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;
warn "curve ", dump @curve;
my $i = 0;
@@
-61,6
+63,7
@@
sub handle_events {
} elsif ( $type == SDL_MOUSEBUTTONUP() ) {
warn "mouse up ", $event->button_x, ' ', $event->button_y;
$mouse_down = 0;
} 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() ) {
} elsif ( $type == SDL_QUIT() ) {
exit;
} elsif ( $type == SDL_KEYDOWN() ) {
@@
-93,6
+96,7
@@
sub handle_events {
$last_y = $y;
} else {
$mouse_down = 0;
$last_y = $y;
} else {
$mouse_down = 0;
+ curve;
}
}
} else {
}
}
} else {