Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Switch julia from an awkward method to a sensible inner sub.

  • Loading branch information...
commit 557cc83048f1909f2ba5eb02a85ff06e554ed10e 1 parent a4d1ba8
Solomon Foster authored
Showing with 14 additions and 13 deletions.
  1. +14 −13 bin/gtk-mandelbrot.pl
27 bin/gtk-mandelbrot.pl
View
@@ -197,6 +197,19 @@
my $ur = $.upper-right;
my $width = $.width;
my $delta = $.delta;
+ my $max_iterations = $.max_iterations;
+
+ sub julia(Complex $c, Complex $z0) {
+ my $z = $z0;
+ my $i;
+ loop ($i = 0; $i < $max_iterations; $i++) {
+ if $z.abs > 2 {
+ return $i + 1;
+ }
+ $z = $z * $z + $c;
+ }
+ return 0;
+ }
my @rows = @.rows = ByteArray.new($width * 3) xx $.height;
@@ -211,7 +224,7 @@
my $c = $ur - $y * $delta * i;
while $counter < $counter_end {
- my $value = $is-julia ?? self.julia($julia-z0, $c) !! self.julia($c, 0i);
+ my $value = $is-julia ?? julia($julia-z0, $c) !! julia($c, 0i);
$row.Set($counter++, @red[$value % 72]);
$row.Set($counter++, @green[$value % 72]);
$row.Set($counter++, @blue[$value % 72]);
@@ -283,18 +296,6 @@
$window.ShowAll;
}
- method julia(Complex $c, Complex $z0) {
- my $z = $z0;
- my $i;
- loop ($i = 0; $i < $.max_iterations; $i++) {
- if $z.abs > 2 {
- return $i + 1;
- }
- $z = $z * $z + $c;
- }
- return 0;
- }
-
my $file-count = 0;
method write-file() {
Please sign in to comment.
Something went wrong with that request. Please try again.