#!/usr/bin/perl -w # # "lines.pl" -- draws random colored lines using Logo, either with # a wrap of 1 (torus) or a wrap of 2 (reflection). # # 070116 by liverpole # # Strict use strict; use warnings; # Libraries use lib "."; use Language::Logo; use File::Basename; use Data::Dumper; use Getopt::Long; # User-defined my $nticks = 100; # Change color after nticks my $tickcnt = 0; # Number of ticks so far my $color = 'yellow'; # Starting pen color my $size = 2; # Pen size my $maxsize = 16; # Maximum pen size my $mindis = 5; # Minimum distance to advance my $maxdis = 50; # Maximum distance to advance my $width = 500; # Screen width my $height = 500; # Screen height my $dist = 9999; # Distance to move forward # Globals my $iam = basename $0; my $b_reflect = 0; my $syntax = " syntax: $iam [switches] Tests round-world scenarios with lines which continuously change angles. Each time the color changes, a new random angle between and is chosen, and the line is rotated by that amount. Switches: -r ............ reflect mode (wrap 2) instead of torus mode (wrap 1) Try, for example, one of: $iam 29 31 $iam 85 95 $iam 170 190 "; # Command-line my $result = GetOptions( "r" => \$b_reflect, ); $result or die $syntax; (my $minang = shift) or die $syntax; (my $maxang = shift) or die $syntax; # Main program # Create Logo object my $lo = new Logo(width => $width, height => $height); my $wrap = $b_reflect? 2: 1; $lo->command("wrap $wrap"); $lo->command("update 5"); $lo->command("pu"); # Pen-up $lo->command("setx random 0 800"); # Choose random x-coordinate $lo->command("sety random 0 800"); # Choose random y-coordinate $lo->command("rt random 0 360"); # Make a random turn $lo->command("pendown; color $color"); # Start drawing $lo->command("ht"); # Hide turtle while (1) { if (++$size > $maxsize) { $size = 1; $lo->command("cs"); } $lo->command("ps $size"); $lo->command("color random"); $lo->command("fd $dist"); $lo->command("rt random $minang $maxang"); }