|
Post by matthew on Sept 27, 2006 6:07:17 GMT -5
Okay here is a short Programme that will draw a Fractal on your Screen, the programme isn't perfect by any means. Currently the only way to Exit the programme is by using the Task Manager. (This is probably because of the way I have set the Code out ). The Mathematical routine for drawing the Fractal is a bit simplistic and therefore slow (about 5 Minutes to Draw) and the Graphics aren't very colourful. When you Run it you should get something like this displayed on your Monitor Screen. OPTION Explicit
DIM AppRun : AppRun = TRUE
DIM X, Y, N, Xh, Yh, Zrh, Zih, Zroh, A
SUB Main()
IF (Graphics.Initialize <> TRUE) THEN EXIT SUB graphics.setTitle "Mandelbrot Fractal - Use Task Manager to Exit" Graphics.SetViewPort 0, 0, 640, 480 Key.Initialize Mouse.Initialize Graphics.Clear &h00000000 For X = 0 TO 639 For Y = 0 TO 479 Xh = -2.0 + X / 163.84 Yh = 1.6 - Y / 153.60 N = 0 Zrh = 0 Zih = 0 Do Until ((Zrh * Zrh) + (Zih * Zih)) > 4 Or N = 16 Zroh = (Zrh * Zrh) - (Zih * Zih) + Xh Zih = 2 * Zrh * Zih + Yh Zrh = Zroh N = N + 1 Loop A = Sin (N * 9) Graphics.SetLine X, Y, X+1, Y+1, A Graphics.Display Next Next Do While AppRun = TRUE IF Key.Pressed(1) Or Key.Pressed(0) = TRUE THEN AppRun = FALSE Loop Graphics.Terminate Mouse.Terminate Key.Terminate End SUB
CALL Main
|
|
|
Post by u9 on Sept 28, 2006 12:23:03 GMT -5
if you add a system.processMessages inside the last loop the application becomes much more responsive (when done drawing). Anyways, nice demo. I like fractals
|
|
|
Post by matthew on Sept 28, 2006 14:33:09 GMT -5
Thank's for the advice, I tried adding that Command inside the Loop and it worked.
|
|
|
Post by Guilect on Oct 8, 2006 10:41:29 GMT -5
Good job matthew. hope you don't mind but I changed the code a bit. First I added a bunch of statements (system.processmessages) in all of the loops to make the app more responsive. Next, I added another keypress watch so that the user can easily exit the app. Thirdly, I changed the the statement from graphics.setline to graphics.setrect which is quicker (although most of the slowness is most likey do to the fact that every pixel on the screen is being drawn to. Need some calculation optimization to improve the speed.). And lastly I added some grey scaling to image to give it some 'color'.
Still takes a few minutes to complete. Just start it. Let it stay as the top visible app. Go get up from the computer and stretch. Then come back and observe.
Cheers.
OPTION Explicit
DIM AppRun : AppRun = TRUE
DIM X, Y, N, Xh, Yh, Zrh, Zih, Zroh, A
SUB Main()
IF (Graphics.Initialize <> TRUE) THEN EXIT SUB graphics.setTitle "Mandelbrot Fractal" Key.Initialize Graphics.Clear &h000000 For X = 0 TO 639 For Y = 0 TO 479 Xh = -2.0 + X / 163.84 Yh = 1.6 - Y / 153.60 N = 0 Zrh = 0 Zih = 0 Do Until ((Zrh * Zrh) + (Zih * Zih)) > 4 Or N = 16 Zroh = (Zrh * Zrh) - (Zih * Zih) + Xh Zih = 2 * Zrh * Zih + Yh Zrh = Zroh N = N + 1 system.processMessages Loop Graphics.SetRect X, Y, 1, 1, ARGB(255,N*15,N*15,N*15) Graphics.Display Next IF Key.Pressed(1) Or Key.Pressed(0) = TRUE THEN AppRun = FALSE Exit For end if system.processMessages Next Do While AppRun = TRUE IF Key.Pressed(1) Or Key.Pressed(0) = TRUE THEN AppRun = FALSE system.processMessages Loop Graphics.Terminate Key.Terminate
End SUB
CALL Main
|
|
|
Post by matthew on Oct 8, 2006 12:18:18 GMT -5
Good Re-Write ;D. When I usually create a Fractal I tend to use a Grey-Scale Palette but as this was the first programme I had created in Brutus2D I didn't know how to. I've also got the Code for a 'Julia Fractal', when I get around to Re-Writing it in Brutus2D I'll place the Code on the Forum.
|
|