blob: 8030ff0028407cfe0934e4d931bf3d79c9fcde48 [file] [log] [blame]
cristy16631fc2009-10-16 14:54:23 +00001package
cristy16631fc2009-10-16 14:54:23 +00002 Turtle;
cristy3ed852e2009-09-05 21:47:34 +00003
cristy60712662009-10-21 00:51:53 +00004# Written by jreed@itis.com, adapted by Cristy.
cristy3ed852e2009-09-05 21:47:34 +00005
6sub new
7{
8 my $class = shift;
9 my $self = {};
10
11 @{$self}{qw(x y theta mirror)} = @_;
12 bless $self, $class;
13}
14
15sub forward
16{
17 my $self = shift;
18 my ($r, $what) = @_;
19 my ($newx, $newy)=($self->{x}+$r* sin($self->{theta}),
20 $self->{y}+$r*-cos($self->{theta}));
21 if ($what) {
22 &$what($self->{x}, $self->{y}, $newx, $newy); # motion
23 }
24 # According to the coderef passed in
25 ($self->{x}, $self->{y})=($newx, $newy); # change the old coords
26}
27
28sub turn
29{
30 my $self = shift;
31 my $dtheta = shift;
32
33 $self->{theta} += $dtheta*$self->{mirror};
34}
35
36sub state
37{
38 my $self = shift;
39
40 @{$self}{qw(x y theta mirror)};
41}
42
43sub setstate
44{
45 my $self = shift;
46
47 @{$self}{qw(x y theta mirror)} = @_;
48}
49
50sub mirror
51{
52 my $self = shift;
53
54 $self->{mirror} *= -1;
55}
56
57"Turtle.pm";