random_abstract_art.pl 752 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. use List::Util qw(shuffle);
  14. my $max = 1_000_000;
  15. my $limit = int(sqrt($max));
  16. say "Possible combinations: $limit!";
  17. # create a new image
  18. my $img = GD::Simple->new($limit * 3, $limit * 3);
  19. # move to the center
  20. $img->moveTo($limit * 1.5, $limit * 1.5);
  21. my $i = 1;
  22. my $j = 1;
  23. for my $m (shuffle(1 .. $limit)) {
  24. for my $n ($j .. $i**2) {
  25. $img->line(1);
  26. $img->turn($n**2 / $m);
  27. ++$j;
  28. }
  29. ++$i;
  30. }
  31. open my $fh, '>:raw', "random_abstract_art.png";
  32. print $fh $img->png;
  33. close $fh;