interaktiver Mandelbrot zoomer
Übersicht BlitzMax, BlitzMax NG Codearchiv & Module
KrümelBetreff: interaktiver Mandelbrot zoomer |
Mi, Mai 23, 2007 1:24 Antworten mit Zitat |
|
---|---|---|
Fraktale finde ich immer wieder faszinierend, deshalb hab ich einen einfachen interaktiven Mandelbrot zoomer programiert.
Maussteuerung , Mausrad=zoom (Das Programm ist mit der BlitzMax Demo entstanden, ich habs zuerst in Blitz3D versucht, aber leider kann man da wegen den 32 Bit Floats nicht so schön weit reinzoomen) *EDIT* - code aufgeräumt , mehr speed Code: [AUSKLAPPEN] 'MANDELBROT ZOOMER - Krümel 05 / 2007 '------------------------------------ 'Controls: 'Mouse - movement 'Mousewheel - zoom 'Key UP / Down - increase / decrease depth 'Key SPACE - change palette SuperStrict Const wid:Int = 640 , hig:Int = 480 , widH:Int = wid * 0.5 , higH:Int = hig * 0.5 Global limit:Int = 4 , res:Int = 4 , nAdd:Int = 0 , nMax:Int = 800 Global px:Double = -100 , py:Double = 0 , pz:Int = MouseZ() , sc:Double = 0.005 Global mxs:Int , mys:Int , mzs:Int Global col:Byte[10000 , 3] Function palette() Local r:Int , g:Int , b:Int , t:Int , c:Int = 10 Local ra:Int = Rnd(-c , c) , ga:Int = Rnd(-c , c) , ba:Int = Rnd(-c , c) For t = 0 To 9999 col[t , 0] = r ; r:+ ra ; If r < 0 r = 0 ; ra = Rand(c) Else If r > 255 r = 255 ; ra = -Rand(c) col[t , 1] = g ; g:+ ga ; If g < 0 g = 0 ; ga = Rand(c) Else If g > 255 g = 255 ; ga = -Rand(c) col[t , 2] = b ; b:+ ba ; If b < 0 b = 0 ; ba = Rand(c) Else If b > 255 b = 255 ; ba = -Rand(c) Next End Function Function mouse:Int() Local ret:Int = False If KeyHit(KEY_ESCAPE) End If KeyHit(KEY_UP) nMax:+ 50 ; ret = True If KeyHit(KEY_DOWN) If nMax > 300 nMax:-50 ; ret = True If KeyHit(KEY_SPACE) palette() ; ret = True mxs=(MouseX() - widH) mys=(MouseY() - higH) mzs=(MouseZ() - pz) ; pz = MouseZ() MoveMouse widH , higH If (mxs <> 0 Or mys <> 0 Or mzs <> 0) px:+ mxs py:+ mys If mzs > 0 sc:* 0.5 ; px:+ (px - widH * sc); py:+ (py - higH * sc) If mzs < 0 sc:* 2.0 ; px:- (px - widH * sc) * 0.5 ; py:- (py - higH * sc) * 0.5 ret = True EndIf If ret = True res = 5 ; Return True If res > 1 res = res - 1 Return False End Function Function mandelbrot:Int(ax:Double , ay:Double) Local a1:Double = ax , b1:Double = ay , a2:Double , n:Int = 0 Repeat a2 = a1 * a1 - b1 * b1 + ax b1 = 2 * a1 * b1 + ay n:+ 1 ; a1 = a2 Until (n > nMax) Or (a1 * a1 + b1 * b1) > limit Return n End Function Function draw(cx:Double , cy:Double , scale:Double) Local ax:Double , ay:Double , x:Int , y:Int , mMove:Int , n:Long y=- higH ; Repeat ay = (cy + y) * scale x=- widH ; Repeat ax = (cx + x) * scale n = mandelbrot(ax , ay) If n < nMax SetColor col[n , 0] , col[n , 1] , col[n , 2] DrawRect x + widH , y + higH , res , res EndIf x:+ res ; Until x >= widH If mMove = 0 mMove = mouse() y:+ res ; Until y >= higH End Function Graphics wid , hig , 0 MoveMouse widH , higH palette() While Not KeyHit(KEY_ESCAPE) draw(px , py , sc) Flip Cls Wend |
||
Übersicht BlitzMax, BlitzMax NG Codearchiv & Module
Powered by phpBB © 2001 - 2006, phpBB Group