mirror_shells.pl 702 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/usr/bin/perl
  2. # Author: Daniel "Trizen" Șuteu
  3. # License: GPLv3
  4. # Date: 30 April 2014
  5. # Website: https://github.com/trizen
  6. use 5.010;
  7. use strict;
  8. use warnings;
  9. use GD::Simple;
  10. my $img = 'GD::Simple'->new(1000, 600);
  11. $img->moveTo(220, 240); # hopefully, at the center of the image
  12. sub t($) {
  13. $img->turn(shift);
  14. }
  15. sub l($) {
  16. $img->line(shift);
  17. }
  18. sub c($) {
  19. $img->fgcolor(shift);
  20. }
  21. my $loop = 50;
  22. t 260;
  23. # From inside-out
  24. for my $j (1 .. $loop) {
  25. l $j;
  26. t $loop- $j + 1;
  27. }
  28. t 180;
  29. # From outside-in
  30. for my $j (1 .. $loop) {
  31. l $loop- $j + 1;
  32. t $j;
  33. }
  34. my $image_name = "mirror_shells.png";
  35. open my $fh, '>', $image_name or die $!;
  36. print {$fh} $img->png;
  37. close $fh;