]> git.imager.perl.org - imager.git/blob - spot.perl
add new comparison method rgb_difference that resembles arithmetical difference per...
[imager.git] / spot.perl
1 #!perl -w
2 # takes spot function and builds an ordered dither 8x8 matrix
3 use strict;
4 my $func = shift or die "Usage: $0 function [width height expandx expandy]\n";
5 my $width = shift || 8;
6 my $height = shift || 8;
7 my @spot;
8 for my $y (0..$height-1) {
9   for my $x (0..$width-1) {
10     my $res = eval $func;
11     $spot[$x+$y*$width] = $res * $res;
12   }
13 }
14 my @sp;
15 @sp[sort { $spot[$a] <=> $spot[$b] } (0.. $#spot)] = 0..$#spot;
16
17 while (@sp) {
18   print "   ",map(sprintf("%4d,", 4*$_), splice(@sp, 0, $width)),"\n";
19 }
20
21 sub min {
22   my (@data) = @_;
23   my $min = shift @data;
24   for (@data) {
25     $min = $_ if $_ < $min;
26   }
27   $min;
28 }
29
30 sub dist {
31   my ($x1, $y1) = @_;
32   return ($x1-$x)*($x1-$x) + ($y1-$y)*($y1-$y);
33 }
34
35 sub theta {
36   my ($x1, $y1) = @_;
37
38   return atan2($y1-$y, $x1-$x);
39 }
40
41 sub dt {
42   my ($x1, $y1) = @_;
43   dist($x1, $y1)+theta($x1,$y1)/20;
44 }