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