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