complex_square.pl 741 B

123456789101112131415161718192021222324252627282930313233
  1. #!/usr/bin/perl
  2. # Author: Daniel "Trizen" Șuteu
  3. # Date: 07 January 2016
  4. # License: GPLv3
  5. # Website: https://github.com/trizen
  6. # Illustration of the complex square root function
  7. use 5.010;
  8. use strict;
  9. use warnings;
  10. use Imager;
  11. use Math::AnyNum;
  12. my $img = Imager->new(xsize => 2000, ysize => 1500);
  13. my $white = Imager::Color->new('#ffffff');
  14. my $black = Imager::Color->new('#000000');
  15. $img->box(filled => 1, color => $black);
  16. for my $i (1 .. 400) {
  17. for my $j (1 .. 400) {
  18. my $x = Math::AnyNum->new_c($i, $j)->sqrt;
  19. my ($re, $im) = ($x->real->numify, $x->imag->numify);
  20. $img->setpixel(x => 300 + int(60 * $re), y => 400 + int(60 * $im), color => $white);
  21. }
  22. }
  23. $img->write(file => 'complex_square.png');