Skip to content

Commit 8b35d82

Browse files
committed
Complex struct is faster now
1 parent 982a9d1 commit 8b35d82

File tree

2 files changed

+4
-27
lines changed

2 files changed

+4
-27
lines changed

contributed/library/simple_complex/simple_complex.rb

Lines changed: 0 additions & 21 deletions
This file was deleted.

contributed/mandelbrot.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
# map1d (instead of map), and a somewhat optimized (update_pixels instead of
55
# set), and using grid, rather than nested loops
66

7-
load_library :simple_complex
8-
97
def setup
108
sketch_title 'Mandelbrot'
119
load_pixels
@@ -15,7 +13,7 @@ def setup
1513
# main drawing method
1614
def draw
1715
grid(900, 600) do |x, y|
18-
c = SimpleComplex.new(
16+
c = Complex(
1917
map1d(x, (0...900), (-3..1.5)), map1d(y, (0...600), (-1.5..1.5))
2018
)
2119
# mandel will return 0..20 (20 is strong) map this to 255..0 (NB: reverse)
@@ -28,11 +26,11 @@ def draw
2826
# how many iterations the number survives without becoming chaotic
2927
def mandel(z, max = 10)
3028
score = 0
31-
c = z.clone
29+
c = z
3230
while score < max
3331
# z = z^2 + c
34-
z.square!
35-
z.add! c
32+
z *= z
33+
z += c
3634
break if z.abs > 2
3735
score += 1
3836
end

0 commit comments

Comments
 (0)