SdlBasic Julia set

This is a julia set with cool colors anf functions to change HSV to RGB. Enjoy.

setDisplay(400, 300, 32, 1)
setCaption("Julia set")
setautoback(1)

common h=0:s=0:v=0:r=0:g=0:b=0

sub colorHSV(hc,sc, vc)
h = hc
s = sc
v = vc
end sub

function HSVtoRGB()
hs = h
ss = s / 255.0
vv = v
if(ss = 0.0) then
r = vv
g = vv
b = vv
else
hs = hs / 60
i  = floor(hs)
f = hs -i

p = vv *(1.0-ss)
q = vv *(1.0-(ss*f))
t = vv *(1.0-(ss*(1.0-f)))

select case i
case 0
r=vv:g=t:b=p
case 1
r=q:g=vv:b=p
case 2
r=p:g=vv:b=t
case 3
r=p:g=q:b=vv
case 4
r=t:g=p:b=vv
case 5
r=vv:g=p:b=q
case else
r=0:g=0:b=0
end select
end if
r=int(r)
g=int(g)
b=int(b)
end function

zoom = 1
moveX = 0
moveY = 0
maxIterations = 300

cRe = -0.7
cIm = 0.27015

for y = 0 to screenHeight()
for x = 0 to screenWidth()
newRe = 1.5 * (x - screenWidth() / 2) / (0.5 * zoom * screenWidth()) + moveX
newIm = (y - screenHeight() / 2) / (0.5 * zoom * screenHeight()) + moveY
for i = 0 to maxIterations
oldRe = newRe
oldIm = newIm

newRe = oldRe * oldRe - oldIm * oldIm + cRe
newIm = 2 * OldRe * oldIm + cIm

if((newRe * newRe + newIm * newIm) > 4) then:exit for:end if
next
'col = rgb(i % 256, 255, 255*(i < maxIterations))
colorHSV(i%256, 255, 255*(i < maxIterations))
HSVtoRGB()
ink(rgb(r, g, b))
dot(x, y)
'plot(x, y, rgb(r, g, b))
'plot(x, y, rgb(i%256, 255, 255*(i<maxIterations)))
next
next
waitVbl()
waitKey(27)</code>

julia_set

SdlBasic Forum

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s