line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyright 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Kevin Ryde |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# This file is part of Math-PlanePath. |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# Math-PlanePath is free software; you can redistribute it and/or modify |
6
|
|
|
|
|
|
|
# it under the terms of the GNU General Public License as published by the |
7
|
|
|
|
|
|
|
# Free Software Foundation; either version 3, or (at your option) any later |
8
|
|
|
|
|
|
|
# version. |
9
|
|
|
|
|
|
|
# |
10
|
|
|
|
|
|
|
# Math-PlanePath is distributed in the hope that it will be useful, but |
11
|
|
|
|
|
|
|
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
12
|
|
|
|
|
|
|
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
13
|
|
|
|
|
|
|
# for more details. |
14
|
|
|
|
|
|
|
# |
15
|
|
|
|
|
|
|
# You should have received a copy of the GNU General Public License along |
16
|
|
|
|
|
|
|
# with Math-PlanePath. If not, see . |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# math-image --path=FibonacciWordFractal --output=numbers_dash |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
package Math::PlanePath::FibonacciWordFractal; |
23
|
1
|
|
|
1
|
|
9159
|
use 5.004; |
|
1
|
|
|
|
|
10
|
|
24
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
25
|
|
25
|
|
|
|
|
|
|
|
26
|
1
|
|
|
1
|
|
4
|
use vars '$VERSION', '@ISA'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
66
|
|
27
|
|
|
|
|
|
|
$VERSION = 128; |
28
|
1
|
|
|
1
|
|
656
|
use Math::PlanePath; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
29
|
1
|
|
|
1
|
|
391
|
use Math::PlanePath::Base::NSEW; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
41
|
|
30
|
|
|
|
|
|
|
@ISA = ('Math::PlanePath::Base::NSEW', |
31
|
|
|
|
|
|
|
'Math::PlanePath'); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
use Math::PlanePath::Base::Generic |
34
|
1
|
|
|
|
|
44
|
'is_infinite', |
35
|
1
|
|
|
1
|
|
5
|
'round_nearest'; |
|
1
|
|
|
|
|
2
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# uncomment this to run the ### lines |
38
|
|
|
|
|
|
|
#use Smart::Comments; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
41
|
1
|
|
|
1
|
|
5
|
use constant n_start => 0; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
43
|
|
42
|
1
|
|
|
1
|
|
5
|
use constant class_x_negative => 0; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
43
|
1
|
|
|
1
|
|
5
|
use constant class_y_negative => 0; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1373
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
my @dir4_to_dx = (0,-1,0,1); |
49
|
|
|
|
|
|
|
my @dir4_to_dy = (1,0,-1,0); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
my $moffset = 0; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub n_to_xy { |
54
|
539
|
|
|
539
|
1
|
2012
|
my ($self, $n) = @_; |
55
|
|
|
|
|
|
|
### FibonacciWordFractal n_to_xy(): $n |
56
|
|
|
|
|
|
|
|
57
|
539
|
50
|
|
|
|
1007
|
if ($n < 0) { return; } |
|
0
|
|
|
|
|
0
|
|
58
|
539
|
50
|
|
|
|
1065
|
if (is_infinite($n)) { return ($n, $n); } |
|
0
|
|
|
|
|
0
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# my $frac; |
61
|
|
|
|
|
|
|
# { |
62
|
|
|
|
|
|
|
# my $int = int($n); |
63
|
|
|
|
|
|
|
# $frac = $n - $int; # inherit possible BigFloat |
64
|
|
|
|
|
|
|
# $n = $int; # BigFloat int() gives BigInt, use that |
65
|
|
|
|
|
|
|
# } |
66
|
|
|
|
|
|
|
{ |
67
|
539
|
|
|
|
|
907
|
my $int = int($n); |
|
539
|
|
|
|
|
804
|
|
68
|
|
|
|
|
|
|
### $int |
69
|
|
|
|
|
|
|
### $n |
70
|
539
|
100
|
|
|
|
945
|
if ($n != $int) { |
71
|
90
|
|
|
|
|
177
|
my ($x1,$y1) = $self->n_to_xy($int); |
72
|
90
|
|
|
|
|
189
|
my ($x2,$y2) = $self->n_to_xy($int+1); |
73
|
90
|
|
|
|
|
149
|
my $frac = $n - $int; # inherit possible BigFloat |
74
|
90
|
|
|
|
|
142
|
my $dx = $x2-$x1; |
75
|
90
|
|
|
|
|
124
|
my $dy = $y2-$y1; |
76
|
90
|
|
|
|
|
294
|
return ($frac*$dx + $x1, $frac*$dy + $y1); |
77
|
|
|
|
|
|
|
} |
78
|
449
|
|
|
|
|
661
|
$n = $int; # BigFloat int() gives BigInt, use that |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
449
|
|
|
|
|
638
|
my $zero = ($n * 0); # inherit bignum 0 |
82
|
449
|
|
|
|
|
656
|
my $one = $zero + 1; # inherit bignum 0 |
83
|
|
|
|
|
|
|
|
84
|
449
|
|
|
|
|
786
|
my @f = ($one, 2+$zero); |
85
|
449
|
|
|
|
|
658
|
my @xend = ($zero, $zero, $one); # F3 N=2 X=1,Y=1 |
86
|
449
|
|
|
|
|
653
|
my @yend = ($zero, $one, $one); |
87
|
449
|
|
|
|
|
589
|
my $level = 2; |
88
|
449
|
|
|
|
|
830
|
while ($f[-1] < $n) { |
89
|
2865
|
|
|
|
|
4131
|
push @f, $f[-1] + $f[-2]; |
90
|
|
|
|
|
|
|
|
91
|
2865
|
|
|
|
|
3896
|
my ($x,$y); |
92
|
2865
|
|
|
|
|
4161
|
my $m = (($level+$moffset) % 6); |
93
|
2865
|
100
|
|
|
|
6095
|
if ($m == 1) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
94
|
341
|
|
|
|
|
456
|
$x = $yend[-2]; # T (transpose) |
95
|
341
|
|
|
|
|
444
|
$y = $xend[-2]; |
96
|
|
|
|
|
|
|
} elsif ($m == 2) { |
97
|
712
|
|
|
|
|
963
|
$x = $yend[-2]; # -90 |
98
|
712
|
|
|
|
|
970
|
$y = - $xend[-2]; |
99
|
|
|
|
|
|
|
} elsif ($m == 3) { |
100
|
602
|
|
|
|
|
841
|
$x = $xend[-2]; # T -90 |
101
|
602
|
|
|
|
|
842
|
$y = - $yend[-2]; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
} elsif ($m == 4) { |
104
|
|
|
|
|
|
|
### T ... |
105
|
423
|
|
|
|
|
575
|
$x = $yend[-2]; # T |
106
|
423
|
|
|
|
|
581
|
$y = $xend[-2]; |
107
|
|
|
|
|
|
|
} elsif ($m == 5) { |
108
|
406
|
|
|
|
|
624
|
$x = - $yend[-2]; # +90 |
109
|
406
|
|
|
|
|
571
|
$y = $xend[-2]; |
110
|
|
|
|
|
|
|
} elsif ($m == 0) { |
111
|
381
|
|
|
|
|
531
|
$x = - $xend[-2]; # T +90 |
112
|
381
|
|
|
|
|
503
|
$y = $yend[-2]; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
2865
|
|
|
|
|
4036
|
push @xend, $xend[-1] + $x; |
116
|
2865
|
|
|
|
|
4038
|
push @yend, $yend[-1] + $y; |
117
|
2865
|
|
|
|
|
5192
|
$level++; |
118
|
|
|
|
|
|
|
### new: ($level%6)." add $x,$y for $xend[-1],$yend[-1] for $f[-1]" |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
449
|
|
|
|
|
616
|
my $x = $zero; |
122
|
449
|
|
|
|
|
592
|
my $y = $zero; |
123
|
449
|
|
|
|
|
614
|
my $rot = 0; |
124
|
449
|
|
|
|
|
573
|
my $transpose = 0; |
125
|
|
|
|
|
|
|
|
126
|
449
|
|
|
|
|
844
|
while (@xend > 1) { |
127
|
|
|
|
|
|
|
### at: "$x,$y rot=$rot transpose=$transpose level=$level n=$n consider f=$f[-1]" |
128
|
3763
|
|
|
|
|
5376
|
my $xo = pop @xend; |
129
|
3763
|
|
|
|
|
4973
|
my $yo = pop @yend; |
130
|
|
|
|
|
|
|
|
131
|
3763
|
100
|
|
|
|
6323
|
if ($n >= $f[-1]) { |
132
|
1183
|
|
|
|
|
1712
|
my $m = (($level+$moffset) % 6); |
133
|
1183
|
|
|
|
|
1569
|
$n -= $f[-1]; |
134
|
|
|
|
|
|
|
### offset: "$xo, $yo for levelmod=$m" |
135
|
|
|
|
|
|
|
|
136
|
1183
|
100
|
|
|
|
1928
|
if ($transpose) { |
137
|
412
|
|
|
|
|
716
|
($xo,$yo) = ($yo,$xo); |
138
|
|
|
|
|
|
|
} |
139
|
1183
|
100
|
|
|
|
2062
|
if ($rot & 2) { |
140
|
475
|
|
|
|
|
626
|
$xo = -$xo; |
141
|
475
|
|
|
|
|
639
|
$yo = -$yo; |
142
|
|
|
|
|
|
|
} |
143
|
1183
|
100
|
|
|
|
1918
|
if ($rot & 1) { |
144
|
475
|
|
|
|
|
779
|
($xo,$yo) = (-$yo,$xo); |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
### apply rot to offset: "$xo, $yo" |
147
|
|
|
|
|
|
|
|
148
|
1183
|
|
|
|
|
1620
|
$x += $xo; |
149
|
1183
|
|
|
|
|
1507
|
$y += $yo; |
150
|
1183
|
100
|
|
|
|
2429
|
if ($m == 1) { # F7 N=13 etc |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
151
|
302
|
|
|
|
|
431
|
$transpose ^= 3; # T |
152
|
|
|
|
|
|
|
} elsif ($m == 2) { # F8 N=21 etc |
153
|
|
|
|
|
|
|
# -90 |
154
|
210
|
100
|
|
|
|
334
|
if ($transpose) { |
155
|
50
|
|
|
|
|
70
|
$rot++; |
156
|
|
|
|
|
|
|
} else { |
157
|
160
|
|
|
|
|
220
|
$rot--; # -90 |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
} elsif ($m == 3) { # F3 N=2 etc |
160
|
|
|
|
|
|
|
# T -90 |
161
|
300
|
100
|
|
|
|
471
|
if ($transpose) { |
162
|
60
|
|
|
|
|
79
|
$rot++; |
163
|
|
|
|
|
|
|
} else { |
164
|
240
|
|
|
|
|
317
|
$rot--; # -90 |
165
|
|
|
|
|
|
|
} |
166
|
300
|
|
|
|
|
441
|
$transpose ^= 3; |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
} elsif ($m == 4) { # F4 N=3 etc |
169
|
126
|
|
|
|
|
182
|
$transpose ^= 3; # T |
170
|
|
|
|
|
|
|
} elsif ($m == 5) { # F5 N=5 etc |
171
|
|
|
|
|
|
|
# +90 |
172
|
125
|
100
|
|
|
|
222
|
if ($transpose) { |
173
|
50
|
|
|
|
|
71
|
$rot--; |
174
|
|
|
|
|
|
|
} else { |
175
|
75
|
|
|
|
|
108
|
$rot++; # +90 |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
} else { # ($m == 0) # F6 N=8 etc |
178
|
|
|
|
|
|
|
# T +90 |
179
|
120
|
100
|
|
|
|
184
|
if ($transpose) { |
180
|
40
|
|
|
|
|
56
|
$rot--; |
181
|
|
|
|
|
|
|
} else { |
182
|
80
|
|
|
|
|
110
|
$rot++; # +90 |
183
|
|
|
|
|
|
|
} |
184
|
120
|
|
|
|
|
185
|
$transpose ^= 3; |
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
} |
187
|
3763
|
|
|
|
|
4801
|
pop @f; |
188
|
3763
|
|
|
|
|
6570
|
$level--; |
189
|
|
|
|
|
|
|
} |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
# mod 6 twist ? |
192
|
|
|
|
|
|
|
# ### final rot: "$rot transpose=$transpose gives ".(($rot^$transpose)&3) |
193
|
|
|
|
|
|
|
# $rot = ($rot ^ $transpose) & 3; |
194
|
|
|
|
|
|
|
# $x = $frac * $dir4_to_dx[$rot] + $x; |
195
|
|
|
|
|
|
|
# $y = $frac * $dir4_to_dy[$rot] + $y; |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
### final with frac: "$x,$y" |
198
|
449
|
|
|
|
|
1034
|
return ($x,$y); |
199
|
|
|
|
|
|
|
} |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
sub xy_to_n { |
202
|
625
|
|
|
625
|
1
|
2843
|
my ($self, $x, $y) = @_; |
203
|
|
|
|
|
|
|
### FibonacciWordFractal xy_to_n(): "$x, $y" |
204
|
|
|
|
|
|
|
|
205
|
625
|
|
|
|
|
1189
|
$x = round_nearest($x); |
206
|
625
|
50
|
|
|
|
1195
|
if (is_infinite($x)) { |
207
|
0
|
|
|
|
|
0
|
return $x; |
208
|
|
|
|
|
|
|
} |
209
|
|
|
|
|
|
|
|
210
|
625
|
|
|
|
|
1444
|
$y = round_nearest($y); |
211
|
625
|
50
|
|
|
|
1102
|
if (is_infinite($y)) { |
212
|
0
|
|
|
|
|
0
|
return $y; |
213
|
|
|
|
|
|
|
} |
214
|
|
|
|
|
|
|
|
215
|
625
|
|
|
|
|
1086
|
my $zero = ($x * 0 * $y); # inherit bignum 0 |
216
|
625
|
|
|
|
|
882
|
my $one = $zero + 1; # inherit bignum 0 |
217
|
|
|
|
|
|
|
|
218
|
625
|
|
|
|
|
1084
|
my @f = ($one, $zero+2); |
219
|
625
|
|
|
|
|
959
|
my @xend = ($zero, $one); # F3 N=2 X=1,Y=1 |
220
|
625
|
|
|
|
|
898
|
my @yend = ($one, $one); |
221
|
625
|
|
|
|
|
853
|
my $level = 3; |
222
|
|
|
|
|
|
|
|
223
|
625
|
|
|
|
|
867
|
for (;;) { |
224
|
4067
|
|
|
|
|
5518
|
my ($xo,$yo); |
225
|
4067
|
|
|
|
|
5495
|
my $m = ($level % 6); |
226
|
4067
|
100
|
|
|
|
8650
|
if ($m == 2) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
227
|
453
|
|
|
|
|
634
|
$xo = $yend[-2]; # T |
228
|
453
|
|
|
|
|
617
|
$yo = $xend[-2]; |
229
|
|
|
|
|
|
|
} elsif ($m == 3) { |
230
|
1003
|
|
|
|
|
1402
|
$xo = $yend[-2]; # -90 |
231
|
1003
|
|
|
|
|
1403
|
$yo = - $xend[-2]; |
232
|
|
|
|
|
|
|
} elsif ($m == 4) { |
233
|
780
|
|
|
|
|
1124
|
$xo = $xend[-2]; # T -90 |
234
|
780
|
|
|
|
|
1035
|
$yo = - $yend[-2]; |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
} elsif ($m == 5) { |
237
|
|
|
|
|
|
|
### T |
238
|
732
|
|
|
|
|
1001
|
$xo = $yend[-2]; # T |
239
|
732
|
|
|
|
|
939
|
$yo = $xend[-2]; |
240
|
|
|
|
|
|
|
} elsif ($m == 0) { |
241
|
630
|
|
|
|
|
1017
|
$xo = - $yend[-2]; # +90 |
242
|
630
|
|
|
|
|
825
|
$yo = $xend[-2]; |
243
|
|
|
|
|
|
|
} elsif ($m == 1) { |
244
|
469
|
|
|
|
|
678
|
$xo = - $xend[-2]; # T +90 |
245
|
469
|
|
|
|
|
657
|
$yo = $yend[-2]; |
246
|
|
|
|
|
|
|
} |
247
|
|
|
|
|
|
|
|
248
|
4067
|
|
|
|
|
5361
|
$xo += $xend[-1]; |
249
|
4067
|
|
|
|
|
5229
|
$yo += $yend[-1]; |
250
|
4067
|
100
|
100
|
|
|
8966
|
last if ($xo > $x && $yo > $y); |
251
|
|
|
|
|
|
|
|
252
|
3442
|
|
|
|
|
5173
|
push @f, $f[-1] + $f[-2]; |
253
|
3442
|
|
|
|
|
4621
|
push @xend, $xo; |
254
|
3442
|
|
|
|
|
4488
|
push @yend, $yo; |
255
|
3442
|
|
|
|
|
4629
|
$level++; |
256
|
|
|
|
|
|
|
### new: "level=$level $xend[-1],$yend[-1] for N=$f[-1]" |
257
|
|
|
|
|
|
|
} |
258
|
|
|
|
|
|
|
|
259
|
625
|
|
|
|
|
878
|
my $n = 0; |
260
|
625
|
|
|
|
|
1163
|
while ($level >= 2) { |
261
|
|
|
|
|
|
|
### at: "$x,$y n=$n level=$level consider $xend[-1],$yend[-1] for $f[-1]" |
262
|
|
|
|
|
|
|
|
263
|
3553
|
|
|
|
|
4920
|
my $m = (($level+$moffset) % 6); |
264
|
3553
|
100
|
|
|
|
5599
|
if ($m >= 3) { |
265
|
|
|
|
|
|
|
### 3,4,5 X ... |
266
|
1818
|
100
|
|
|
|
3059
|
if ($x >= $xend[-1]) { |
267
|
586
|
|
|
|
|
796
|
$n += $f[-1]; |
268
|
586
|
|
|
|
|
786
|
$x -= $xend[-1]; |
269
|
586
|
|
|
|
|
770
|
$y -= $yend[-1]; |
270
|
|
|
|
|
|
|
### shift to: "$x,$y levelmod ".$m |
271
|
|
|
|
|
|
|
|
272
|
586
|
100
|
|
|
|
1414
|
if ($m == 3) { # F3 N=2 etc |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
273
|
269
|
|
|
|
|
468
|
($x,$y) = (-$y,$x); # +90 |
274
|
|
|
|
|
|
|
} elsif ($m == 4) { # F4 N=3 etc |
275
|
157
|
|
|
|
|
209
|
$y = -$y; # +90 T |
276
|
|
|
|
|
|
|
} elsif ($m == 5) { # F5 N=5 etc |
277
|
160
|
|
|
|
|
272
|
($x,$y) = ($y,$x); # T |
278
|
|
|
|
|
|
|
} |
279
|
|
|
|
|
|
|
### rot to: "$x,$y" |
280
|
586
|
100
|
100
|
|
|
1575
|
if ($x < 0 || $y < 0) { |
281
|
118
|
|
|
|
|
286
|
return undef; |
282
|
|
|
|
|
|
|
} |
283
|
|
|
|
|
|
|
} |
284
|
|
|
|
|
|
|
} else { |
285
|
|
|
|
|
|
|
### 0,1,2 Y ... |
286
|
1735
|
100
|
|
|
|
3062
|
if ($y >= $yend[-1]) { |
287
|
828
|
|
|
|
|
1155
|
$n += $f[-1]; |
288
|
828
|
|
|
|
|
1066
|
$x -= $xend[-1]; |
289
|
828
|
|
|
|
|
1038
|
$y -= $yend[-1]; |
290
|
|
|
|
|
|
|
### shift to: "$x,$y levelmod ".$m |
291
|
|
|
|
|
|
|
|
292
|
828
|
100
|
|
|
|
1544
|
if ($m == 0) { # F6 N=8 etc |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
293
|
368
|
|
|
|
|
590
|
($x,$y) = ($y,-$x); # -90 |
294
|
|
|
|
|
|
|
} elsif ($m == 1) { # F7 N=13 etc |
295
|
76
|
|
|
|
|
108
|
$x = -$x; # -90 T |
296
|
|
|
|
|
|
|
} elsif ($m == 2) { # F8 N=21 etc, incl F2 N=1 |
297
|
384
|
|
|
|
|
631
|
($x,$y) = ($y,$x); # T |
298
|
|
|
|
|
|
|
} |
299
|
|
|
|
|
|
|
### rot to: "$x,$y" |
300
|
828
|
100
|
100
|
|
|
2557
|
if ($x < 0 || $y < 0) { |
301
|
222
|
|
|
|
|
577
|
return undef; |
302
|
|
|
|
|
|
|
} |
303
|
|
|
|
|
|
|
} |
304
|
|
|
|
|
|
|
} |
305
|
|
|
|
|
|
|
|
306
|
3213
|
|
|
|
|
4318
|
pop @f; |
307
|
3213
|
|
|
|
|
4192
|
pop @xend; |
308
|
3213
|
|
|
|
|
4132
|
pop @yend; |
309
|
3213
|
|
|
|
|
5540
|
$level--; |
310
|
|
|
|
|
|
|
} |
311
|
|
|
|
|
|
|
|
312
|
285
|
100
|
100
|
|
|
656
|
if ($x != 0 || $y != 0) { |
313
|
196
|
|
|
|
|
436
|
return undef; |
314
|
|
|
|
|
|
|
} |
315
|
89
|
|
|
|
|
203
|
return $n; |
316
|
|
|
|
|
|
|
} |
317
|
|
|
|
|
|
|
|
318
|
|
|
|
|
|
|
# not exact |
319
|
|
|
|
|
|
|
sub rect_to_n_range { |
320
|
0
|
|
|
0
|
1
|
|
my ($self, $x1,$y1, $x2,$y2) = @_; |
321
|
|
|
|
|
|
|
### FibonacciWordFractal rect_to_n_range(): "$x1,$y1 $x2,$y2" |
322
|
|
|
|
|
|
|
|
323
|
0
|
|
|
|
|
|
$x1 = round_nearest ($x1); |
324
|
0
|
|
|
|
|
|
$y1 = round_nearest ($y1); |
325
|
0
|
|
|
|
|
|
$x2 = round_nearest ($x2); |
326
|
0
|
|
|
|
|
|
$y2 = round_nearest ($y2); |
327
|
0
|
0
|
|
|
|
|
($x1,$x2) = ($x2,$x1) if $x1 > $x2; |
328
|
0
|
0
|
|
|
|
|
($y1,$y2) = ($y2,$y1) if $y1 > $y2; |
329
|
|
|
|
|
|
|
### rect_to_n_range(): "$x1,$y1 to $x2,$y2" |
330
|
|
|
|
|
|
|
|
331
|
0
|
0
|
0
|
|
|
|
if ($x2 < 0 || $y2 < 0) { |
332
|
0
|
|
|
|
|
|
return (1, 0); |
333
|
|
|
|
|
|
|
} |
334
|
0
|
|
|
|
|
|
foreach ($x1,$x2,$y1,$y2) { |
335
|
0
|
0
|
|
|
|
|
if (is_infinite($_)) { return (0, $_); } |
|
0
|
|
|
|
|
|
|
336
|
|
|
|
|
|
|
} |
337
|
|
|
|
|
|
|
|
338
|
0
|
|
|
|
|
|
my $zero = ($x1 * 0 * $y1 * $x2 * $y2); # inherit bignum 0 |
339
|
0
|
|
|
|
|
|
my $one = $zero + 1; # inherit bignum 0 |
340
|
|
|
|
|
|
|
|
341
|
0
|
|
|
|
|
|
my $f0 = 1; |
342
|
0
|
|
|
|
|
|
my $f1 = 2; |
343
|
0
|
|
|
|
|
|
my $xend0 = $zero; |
344
|
0
|
|
|
|
|
|
my $xend1 = $one; |
345
|
0
|
|
|
|
|
|
my $yend0 = $one; |
346
|
0
|
|
|
|
|
|
my $yend1 = $one; |
347
|
0
|
|
|
|
|
|
my $level = 3; |
348
|
|
|
|
|
|
|
|
349
|
0
|
|
|
|
|
|
for (;;) { |
350
|
0
|
|
|
|
|
|
my ($xo,$yo); |
351
|
0
|
|
|
|
|
|
my $m = (($level+$moffset) % 6); |
352
|
0
|
0
|
|
|
|
|
if ($m == 3) { # at F3 N=2 etc |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
353
|
0
|
|
|
|
|
|
$xo = $yend0; # -90 |
354
|
0
|
|
|
|
|
|
$yo = - $xend0; |
355
|
|
|
|
|
|
|
} elsif ($m == 4) { # at F4 N=3 etc |
356
|
0
|
|
|
|
|
|
$xo = $xend0; # T -90 |
357
|
0
|
|
|
|
|
|
$yo = - $yend0; |
358
|
|
|
|
|
|
|
|
359
|
|
|
|
|
|
|
} elsif ($m == 5) { # at F5 N=5 etc |
360
|
0
|
|
|
|
|
|
$xo = $yend0; # T |
361
|
0
|
|
|
|
|
|
$yo = $xend0; |
362
|
|
|
|
|
|
|
} elsif ($m == 0) { # at F6 N=8 etc |
363
|
0
|
|
|
|
|
|
$xo = - $yend0; # +90 |
364
|
0
|
|
|
|
|
|
$yo = $xend0; |
365
|
|
|
|
|
|
|
} elsif ($m == 1) { # at F7 N=13 etc |
366
|
0
|
|
|
|
|
|
$xo = - $xend0; # T +90 |
367
|
0
|
|
|
|
|
|
$yo = $yend0; |
368
|
|
|
|
|
|
|
} else { # if ($m == 2) { # at F8 N=21 etc |
369
|
0
|
|
|
|
|
|
$xo = $yend0; # T |
370
|
0
|
|
|
|
|
|
$yo = $xend0; |
371
|
|
|
|
|
|
|
} |
372
|
|
|
|
|
|
|
|
373
|
0
|
|
|
|
|
|
($f1,$f0) = ($f1+$f0,$f1); |
374
|
0
|
|
|
|
|
|
($xend1,$xend0) = ($xend1+$xo,$xend1); |
375
|
0
|
|
|
|
|
|
($yend1,$yend0) = ($yend1+$yo,$yend1); |
376
|
0
|
|
|
|
|
|
$level++; |
377
|
|
|
|
|
|
|
|
378
|
|
|
|
|
|
|
### consider: "f1=$f1 xy end $xend1,$yend1" |
379
|
0
|
0
|
0
|
|
|
|
if ($xend1 > $x2 && $yend1 > $y2) { |
380
|
0
|
|
|
|
|
|
return (0, $f1 - 1); |
381
|
|
|
|
|
|
|
} |
382
|
|
|
|
|
|
|
} |
383
|
|
|
|
|
|
|
} |
384
|
|
|
|
|
|
|
|
385
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
386
|
|
|
|
|
|
|
|
387
|
|
|
|
|
|
|
# ENHANCE-ME: is this good? |
388
|
|
|
|
|
|
|
# |
389
|
|
|
|
|
|
|
# Points which are on alternate X and Y axes |
390
|
|
|
|
|
|
|
# n=0 |
391
|
|
|
|
|
|
|
# 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144 |
392
|
|
|
|
|
|
|
# ^ ^ ^ ^ |
393
|
|
|
|
|
|
|
# 0 4 20 88 |
394
|
|
|
|
|
|
|
# F(2+3*level) |
395
|
|
|
|
|
|
|
# or F(2+6*level) to go X axis each time |
396
|
|
|
|
|
|
|
# |
397
|
|
|
|
|
|
|
# sub level_to_n_range { |
398
|
|
|
|
|
|
|
# my ($self, $level) = @_; |
399
|
|
|
|
|
|
|
# return (0, F(2+3*$level)-1); |
400
|
|
|
|
|
|
|
# } |
401
|
|
|
|
|
|
|
|
402
|
|
|
|
|
|
|
1; |
403
|
|
|
|
|
|
|
__END__ |