News:

PlayBASIC2DLL V0.99 Revision I Commercial Edition released! - Convert PlayBASIC programs to super fast Machine Code. 

Main Menu

appleman

Started by stef, January 26, 2006, 08:29:44 AM

Previous topic - Next topic

stef

Hi!

The example shows the drawing of Mandelbrot fractal.

You must wait a little
(KPix/sec is coming after second turn)

Greetings
stef

PlayBASIC Code: [Select]
; PROJECT : appleman
; AUTHOR : stef
; CREATED : 21.11.2005
; EDITED : 26.01.2013



Global maxiter#=64


w# = 640
h# = 480


openscreen w#, h#, 32, 1
xstart# = -2.025
ystart# = -1.125
xende# = 0.6
yende# = 1.125

fac#=0.99

print "Working"

Sync

do
Cls 0
xende# = xende#*fac#
xstart#=xstart#*fac#
ystart#=ystart#*fac#
yende#=yende#*fac#
xzoom# = (xende# - xstart#) / w#
yzoom# = (yende# - ystart#) / h#

mandelbrot(w#, h#, xstart#, ystart#, xzoom#, yzoom#)

thistime = timer()
Print Str$(Int(w#*h# / (thistime-lasttime))) + " Kpix/sec"
lasttime=thistime
sync
loop
End


Function mandelbrot(w1#, h1#, xstart#, ystart#, xzoom#, yzoom#)

For y = 0 To h1#-1
lockbuffer

YValue#=ystart# + yzoom# * y
For x = 0 To w1#-1

h# = DotsColor(xstart# + xzoom# * x, yValue#)

If h# <> old#
b# = 1.0 - h# * h#
col = HSBtoRGB(h#, 0.8, b#)
old# = h#
EndIf

dotc x,y,col
Next
unlockbuffer
Next

EndFunction


function DotsColor(xval#, yval#)

While j# < maxiter# and abs(r#)<4.0
j#=j#+1.0
m# = r# * r# - i# * i#
i# = 2*r# * i# + yval#
r# = m# + xval#

endwhile

j# = j#/ maxiter#

EndFunction j#


function HSBtoRGB(hue#, saturation#, brightness#)

;If brightness# = 0 Then exitfunction col1= 0
;If saturation# = 0 Then exitfunction col1= RGB(brightness#*255, brightness#*255,brightness#*255)

If hue# < 1.0/6.0
dom# = hue#
red# = brightness#
blue# = brightness# * (1.0 - saturation#)
green# = blue# + (brightness# - blue#) * dom# * 6
Else
If hue# < 2.0/6.0
dom# = hue# - 1.0/6.0
green# = brightness#
blue# = brightness# * (1.0 - saturation#)
red# = green# - (brightness# - blue#) * dom# * 6.0
Else
If hue# < 3.0/6.0
dom# = hue# - 2.0/6.0
green# = brightness#
red# = brightness# * (1.0 - saturation#)
blue# = red# + (brightness# - red#) * dom# * 6.0
Else
If hue# < 4.0/6.0
dom# = hue# - 0.5
blue# = brightness#
red# = brightness# * (1.0 - saturation#)
green# = blue# - (brightness# - red#) * dom# * 6.0
Else
If hue# < 5.0/6.0
dom# = hue# - 5.0/6.0
blue# = brightness#
green# = brightness# * (1.0 - saturation#)
red# = green# + (brightness# - green#) * dom# * 6.0
Else
dom# = hue# - 5.0/6.0
red# = brightness#
green# = brightness# * (1.0 - saturation#)
blue# = red# - (brightness# - green#) * dom# * 6.0
EndIf
EndIf
EndIf
EndIf
EndIf
col1= RGB(red# * 255.0, green# * 255.0, blue# * 255.0)

endFunction col1