HEX
Server: Apache/2.4.62 (Unix) OpenSSL/1.1.1k
System: Linux ns565604.ip-54-39-133.net 4.18.0-553.50.1.el8_10.x86_64 #1 SMP Tue Apr 15 08:09:22 EDT 2025 x86_64
User: greer489 (1034)
PHP: 8.3.19
Disabled: NONE
Upload Files
File: //usr/share/doc/ImageMagick-perl/demo/Turtle.pm
package
  Turtle;

# Written by jreed@itis.com, adapted by Cristy.

sub new
{
  my $class = shift;
  my $self = {};

  @{$self}{qw(x y theta mirror)} = @_;
  bless $self, $class;
}

sub forward
{
  my $self = shift;
  my ($r, $what) = @_;
  my ($newx, $newy)=($self->{x}+$r* sin($self->{theta}),
                     $self->{y}+$r*-cos($self->{theta}));
  if ($what) {
    &$what($self->{x}, $self->{y}, $newx, $newy);  # motion
  }
  # According to the coderef passed in
  ($self->{x}, $self->{y})=($newx, $newy);  # change the old coords
}

sub turn
{
  my $self = shift;
  my $dtheta = shift;

  $self->{theta} += $dtheta*$self->{mirror};
}

sub state
{
  my $self = shift;

  @{$self}{qw(x y theta mirror)};
}

sub setstate
{
  my $self = shift;

  @{$self}{qw(x y theta mirror)} = @_;
}

sub mirror
{
  my $self = shift;

  $self->{mirror} *= -1;
}

"Turtle.pm";