Commit | Line | Data |
---|---|---|
02d1d628 AMH |
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 | use vars qw($x $y); | |
9 | for $y (0..$height-1) { | |
10 | for $x (0..$width-1) { | |
11 | my $res = eval $func; | |
12 | $spot[$x+$y*$width] = $res * $res; | |
13 | } | |
14 | } | |
15 | my @sp; | |
16 | @sp[sort { $spot[$a] <=> $spot[$b] } (0.. $#spot)] = 0..$#spot; | |
17 | ||
18 | while (@sp) { | |
19 | print " ",map(sprintf("%4d,", 4*$_), splice(@sp, 0, $width)),"\n"; | |
20 | } | |
21 | ||
22 | sub min { | |
23 | my (@data) = @_; | |
24 | my $min = shift @data; | |
25 | for (@data) { | |
26 | $min = $_ if $_ < $min; | |
27 | } | |
28 | $min; | |
29 | } | |
30 | ||
31 | sub dist { | |
32 | my ($x1, $y1) = @_; | |
33 | return ($x1-$x)*($x1-$x) + ($y1-$y)*($y1-$y); | |
34 | } | |
35 | ||
36 | sub theta { | |
37 | my ($x1, $y1) = @_; | |
38 | ||
39 | return atan2($y1-$y, $x1-$x); | |
40 | } | |
41 | ||
42 | sub dt { | |
43 | my ($x1, $y1) = @_; | |
44 | dist($x1, $y1)+theta($x1,$y1)/20; | |
45 | } |