Anonymous user
Simple turtle graphics: Difference between revisions
→{{header|Perl}}
m (→{{header|Phix}}: fixed the canvas resize issue (by replaciung the uploaded version of pGUI.js)) |
|||
Line 140:
=={{header|Perl}}==
Added octangle window to house attic.
<lang perl>#!/usr/bin/perl
Line 147 ⟶ 148:
use List::Util qw( max );
my $
sub dsin { sin $_[0] / $radian }▼
sub dcos { cos $_[0] / $radian }▼
# turtle routines
my $mw = MainWindow->new;▼
my $c = $mw->Canvas(▼
-width => 900, -height => 900,▼
)->pack;▼
$mw->Button(-text => 'Exit', -command => sub {$mw->destroy},▼
)->pack(-fill => 'x');▼
my $pen = 1; # true for pendown, false for penup
my @location = (0, 0); # upper left corner
my $direction = 0; # 0 for East, increasing clockwise
$mw->after(0, \&run);▼
MainLoop;▼
-M $0 < 0 and exec $0;▼
my @stack;
my $radian = 180 / atan2 0, -1;
▲sub dsin { sin $_[0] / $radian }
▲sub dcos { cos $_[0] / $radian }
sub save { push @stack, [ $direction, @location ] }
sub restore { ($direction, @location) = @{ pop @stack } }
Line 182 ⟶ 174:
sub penup { $pen = 0 }
sub pendown { $pen = 1 }
sub text { $c->createText( @location, -text => shift ) }▼
# make window
{▼
▲my $mw = MainWindow->new;
▲ $c->createText( @location, -text => shift )
}▼
▲ -width => 900, -height => 900,
▲ )->pack;
▲$mw->Button(-text => 'Exit', -command => sub {$mw->destroy},
▲ )->pack(-fill => 'x');
▲$mw->after(0, \&run);
▲MainLoop;
▲-M $0 < 0 and exec $0;
sub box
Line 218:
pendown;
box $size / 4, $size / 2;
penup;
forward $size * 3 / 8;
left 90;
forward $size / 4;
right 90;
pendown;
box $size / 4, $size / 4;
penup;
restore;
save;
forward $size / 2;
left 90;
forward $size + 40;
right 90;
pendown;
for (1 .. 8)
▲ {
forward 15;
left 45;
forward 15;
▲ }
restore;
penup;
}
|