Julia Set Fractal
Author |
Message |
Geniis
|
Posted: Fri Mar 12, 2010 9:24 pm Post subject: Julia Set Fractal |
|
|
Well heres the julia set genrator i said id make:
Turing: |
setscreen ("graphics:400;400")
for i : 0 .. 255
RGB.SetColor (i, (i ** 2 / 255), (i ** 2) / 255, (255 - i ) / 255)
end for
const Black := RGB.AddColor (0, 0, 0)
Text.Color (Black )
type CNum :
record
r, i : real
end record
fcn CAdd (a, b : CNum ) : CNum
var c := a
c.r + = b.r
c.i + = b.i
result c
end CAdd
fcn CSub (a, b : CNum ) : CNum
var c := a
c.r - = b.r
c.i - = b.i
result c
end CSub
fcn CMult (a, b : CNum ) : CNum
var c : CNum
c.r := a.r * b.r - a.i * b.i
c.i := a.r * b.i + b.r * a.i
result c
end CMult
proc GenJulia (minX, minY, maxX, maxY : real, deg, magnitude, depth : int, cr, ci : real)
%minX and minY : the minimum x and y boundaries
%maxX and maxY : the maximum x and y boundaries
%deg : the degree of the julia fractal (recomende left at 4)
%magnitude : the magnitude of the fractal (higher = better prediction = more time)
%depth : max number of iterations befor calling it infinite
%cr and ci : the complex constant for the set. Different constants generate different images.
var z, t, c : CNum
c.r := cr
c.i := ci
var p : real
var n : nat := 0
drawfillbox (0, 0, maxx, maxy, Black )
var xcoef := (maxx + 1) / (maxX - minX )
var ycoef := (maxy + 1) / (maxY - minY )
for x : 0 .. maxx
for y : 0 .. maxy
z.r := x / xcoef + minX
z.i := y / ycoef + minY
n := 0
loop
n + = 1
exit when z.r ** 2 + z.i ** 2 > magnitude or n = depth
t := z
for i : 2 .. deg
t := CMult (t, z )
end for
z := CAdd (t, c )
end loop
if n not= depth then
drawdot (x, y, n )
end if
end for
end for
end GenJulia
GenJulia (- 1, - 1, 1, 1, 2, 4, 255, 0. 285, 0)
|
Play around with it it gets interesting when you go into higher degrees... but also slower.
EDIT: forgot to put Turing in the sytax tag quotes lol
EDIT2: quick bugfix (min/max X and Y were wrong type) |
|
|
|
|
|
Sponsor Sponsor
|
|
|
|
|