random_abstract_art_2.pl 716 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/usr/bin/perl
  2. # Author: Daniel "Trizen" Șuteu
  3. # License: GPLv3
  4. # Date: 08 June 2015
  5. # https://github.com/trizen
  6. #
  7. ## Generate complex random art based on simple mathematics.
  8. #
  9. use 5.010;
  10. use strict;
  11. use warnings;
  12. use GD::Simple;
  13. my $max = 1_000_000;
  14. my $limit = int(sqrt($max));
  15. # create a new image
  16. my $img = GD::Simple->new($limit * 3, $limit * 3);
  17. # move to the center
  18. $img->moveTo($limit * 1.5, $limit * 1.5);
  19. my $i = 1;
  20. my $j = 1;
  21. for my $m (map { rand($limit) - rand($limit) } (1 .. $limit)) {
  22. for my $n ($j .. $i**2) {
  23. $img->line(1);
  24. $img->turn($n**2 / $m);
  25. ++$j;
  26. }
  27. ++$i;
  28. }
  29. open my $fh, '>:raw', "random_abstract_art_2.png";
  30. print $fh $img->png;
  31. close $fh;