line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Math::Fractal::Julia; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$Math::Fractal::Julia::VERSION = '0.000003'; |
4
|
|
|
|
|
|
|
} |
5
|
3
|
|
|
3
|
|
800410
|
use strict; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
111
|
|
6
|
3
|
|
|
3
|
|
14
|
use warnings; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
557
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# ABSTRACT: Calculate points in the Julia set |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
require XSLoader; |
11
|
|
|
|
|
|
|
XSLoader::load( 'Math::Fractal::Julia', $Math::Fractal::Julia::VERSION ); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
1
|
|
|
1
|
1
|
561
|
my ( $class, %options ) = @_; |
15
|
|
|
|
|
|
|
|
16
|
1
|
|
|
|
|
12
|
my $julia = $class->_new(); |
17
|
|
|
|
|
|
|
|
18
|
1
|
|
|
|
|
7
|
while ( my ( $key, $value ) = each %options ) { |
19
|
0
|
|
|
|
|
0
|
my $method = 'set_' . $key; |
20
|
0
|
0
|
|
|
|
0
|
if ( ref $value ) { |
21
|
0
|
|
|
|
|
0
|
$julia->$method(@$value); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
else { |
24
|
0
|
|
|
|
|
0
|
$julia->$method($value); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
1
|
|
|
|
|
3
|
return $julia; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
1; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=pod |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 NAME |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
Math::Fractal::Julia - Calculate points in the Julia set |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 VERSION |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
version 0.000003 |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head1 SYNOPSIS |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
use Math::Fractal::Julia; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# Procedural usage: |
50
|
|
|
|
|
|
|
Math::Fractal::Julia->set_max_iter($iters); |
51
|
|
|
|
|
|
|
Math::Fractal::Julia->set_limit($limit); |
52
|
|
|
|
|
|
|
Math::Fractal::Julia->set_bounds( $x1, $y1, $x2, $y2, $w, $h ); |
53
|
|
|
|
|
|
|
Math::Fractal::Julia->set_constant( $cx, $cy ); |
54
|
|
|
|
|
|
|
for my $y ( 0 .. $h - 1 ) { |
55
|
|
|
|
|
|
|
for my $x ( 0 .. $w - 1 ) { |
56
|
|
|
|
|
|
|
my $iter = Math::Fractal::Julia->point( $x, $y ); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# Object Oriented usage: |
61
|
|
|
|
|
|
|
my $julia = Math::Fractal::Julia->new(%options); |
62
|
|
|
|
|
|
|
$julia->set_max_iter($iters); |
63
|
|
|
|
|
|
|
$julia->set_limit($limit); |
64
|
|
|
|
|
|
|
$julia->set_bounds( $x1, $y1, $x2, $y2, $w, $h ); |
65
|
|
|
|
|
|
|
$julia->set_constant( $cx, $cy ); |
66
|
|
|
|
|
|
|
for my $y ( 0 .. $h - 1 ) { |
67
|
|
|
|
|
|
|
for my $x ( 0 .. $w - 1 ) { |
68
|
|
|
|
|
|
|
my $iter = $julia->point( $x, $y ); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 DESCRIPTION |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Calculates points in the set named after the French mathematician Gaston |
75
|
|
|
|
|
|
|
Julia. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
The procedural interface is based on that provided by |
78
|
|
|
|
|
|
|
L. |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 METHODS |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head2 new |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=over 4 |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=item Arguments: %options? |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=item Return value: A Math::Fractal::Julia object |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=back |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Creates a new Math::Fractal::Object. If no options are provided, the |
93
|
|
|
|
|
|
|
default values will be used. |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=over 4 |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=item options |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
The C hash may contain any or all of the following: |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
max_iter => $iters |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
limit => $limit |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
bounds => [ $x1, $x2, $y1, $y2, $width, $height ] |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
constant => [ $cx, $cy ] |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=back |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
The default maximum number of iterations is 600. |
112
|
|
|
|
|
|
|
The default limit is 5. |
113
|
|
|
|
|
|
|
The default bounds is [-2.2, -1.1, 1.0, 1.1, 640, 480]. |
114
|
|
|
|
|
|
|
The default constant is [0.0, 0.0]. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
my $julia = Math::Fractal::Julia->new(); |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
my $julia = Math::Fractal::Julia->new(%options); |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
my $julia = Math::Fractal::Julia->new( |
121
|
|
|
|
|
|
|
max_iter => $iters, |
122
|
|
|
|
|
|
|
limit => $limit, |
123
|
|
|
|
|
|
|
bounds => [ $x1, $x2, $y1, $y2, $width, $height ], |
124
|
|
|
|
|
|
|
constant => [ $cx, $cy ], |
125
|
|
|
|
|
|
|
); |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head2 set_max_iter |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=over 4 |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=item Arguments: $max |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=item Return value: undefined |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=back |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
Set the maximum number of iterations. The default value is 600. |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Math::Fractal::Julia->set_max_iter($max); |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
$julia->set_max_iter($max); |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head2 set_limit |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=over 4 |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=item Arguments: $limit |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=item Return value: undefined |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=back |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
The default value is 5. |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
Math::Fractal::Julia->set_limit($limit); |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
$julia->set_limit($limit); |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head2 set_bounds |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=over 4 |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=item Arguments: $x1, $y1, $x2, $y2, $width, $height |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=item Return value: undefined |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=back |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
Set the bounds of the set. The first four values (C<$x1>, C<$y1>, |
170
|
|
|
|
|
|
|
C<$x2>, C<$y2>) define a rectangle. The remaining two (C<$width>, |
171
|
|
|
|
|
|
|
C<$height>) define a viewport. |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
The default values are (-2.2, -1.1, 1.0, 1.1, 640, 480). |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
Math::Fractal::Julia->set_bounds( $x1, $y1, $x2, $y2, $width, $height ); |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
$julia->set_bounds( $x1, $x2, $y1, $y2, $width, $height ); |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head2 set_constant |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=over 4 |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=item Arguments: $cx, $cy |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=item Return value: undefined |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=back |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
The default values are (0.0, 0.0). |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
Math::Fractal::Julia->set_constant( $cx, $cy ); |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
$julia->set_constant( $cx, $cy ); |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=head2 point |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=over 4 |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=item Arguments: $x, $y |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=item Return value: The number of iterations needed to exceed the limit |
202
|
|
|
|
|
|
|
or 0 if the the limit is not exceeded. |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=back |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
This function translates the coordinates using the bounds and then |
207
|
|
|
|
|
|
|
iterates. |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
$iters = Math::Fractal::Julia->point( $x, $y ); |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
$iters = $julia->point( $x, $y ); |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
=head1 CAVEATS |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=over 4 |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=item * |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
This module is not thread-safe. |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=item * |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
Any packages derived from C will share the same |
224
|
|
|
|
|
|
|
internal state when the procedural interface is used. |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=back |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
=head1 SEE ALSO |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=over 4 |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
=item * L |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
=item * L |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
=back |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=head1 AUTHOR |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
Jeffrey T. Palmer |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
This software is copyright (c) 2012 by Jeffrey T. Palmer. |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
247
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
=cut |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
__END__ |