GL Fractals

Previous topic - Next topic

backslider

Hi guys,

today i wrote a Mandelbrot-algorithm in GLBasic for testing my CPU.
Here is a picture and the source + .exe in the attachments.

If you want to start the animation of an Mandelbrot you have to press the spacebar for 1-5 seconds.
When the animation is started you can leave the button.

Hope my english is OK :D

greets

[attachment deleted by admin]

Hatonastick

Mate your English is just fine.  Probably better than mine. :)

I love fractals, thanks for the example!
Mat. 5: 14 - 16

Android: Toshiba Thrive Tablet (3.2), Samsung Galaxy Tab 2 (4.1.2).
Netbook: Samsung N150+ Netbook (Win 7 32-bit + Ubuntu 11.10).
Desktop: Intel i5 Desktop with NVIDIA GeForce GTX 460 (Win 8.1 64-bit).

backslider

Nice OK :)

Yes I love it, too. But it´s a performance monster! :D

backslider

Now I added some colors to the program.
If sb. wants the source i will update the first upload.

greets

[attachment deleted by admin]

Moru

Great, please update the original upload for all of us :-)

I always wanted to do this but was too stupid.

backslider

OK. It´s now up to date in the first post (Mandelbrot2.rar).

Have fun :)

Moru

Performance tip: Try to use sprites and ALPHAMODE to set the pixels instead of SETPIXEL, might lead to higher performance. I tried something like this but since I'm not able to see the grafics live on the VNC screen, I can't say if it's any faster :-)

Code (glbasic) Select

ALPHAMODE percent-1

DRAWSPRITE 1, s,z

IF val%<5
DRAWSPRITE 1, s,z
ENDIF

IF val%>=5 AND val%<7
DRAWSPRITE 2, s,z
ENDIF

IF val%>=7 AND val%<8
DRAWSPRITE 3, s,z
ENDIF

IF val%>=8 AND val%<11
DRAWSPRITE 4, s,z
ENDIF

IF val%>=11 AND val%<20
DRAWSPRITE 5, s,z
ENDIF

IF val%>=20 AND val%<50
DRAWSPRITE 6, s,z
ENDIF

FUNCTION PrepareSprites:
LOCAL s = 0, z = 0
SETTRANSPARENCY RGB(0,0,0)

CREATESCREEN 0, 1, 16,16
USESCREEN 0
SETPIXEL s,z,RGB(0xcb, 0x1b, 0x1b)

CREATESCREEN 0, 2, 16,16
USESCREEN 0
SETPIXEL s,z,RGB(0xf3, 0xad, 0x1d)

CREATESCREEN 0, 3, 16,16
USESCREEN 0
SETPIXEL s,z,RGB(0xee, 0xc1, 0x6f)

CREATESCREEN 0, 4, 16,16
USESCREEN 0
SETPIXEL s,z,RGB(0x2b, 0x93, 0x1c)

CREATESCREEN 0, 5, 16,16
USESCREEN 0
SETPIXEL s,z,RGB(0x43, 0xbf, 0x2d)

CREATESCREEN 0, 6, 16,16
USESCREEN 0
SETPIXEL s,z,RGB(0x52, 0xf3, 0x5a)

USESCREEN -1
ENDFUNCTION

backslider

Hi Guys,

i renamed the Thread into "GL Fractals"... Why? Because i added a new Fractal called "Pythagoras Tree".
If you don´t know it, here it is with GLBasic-Code ;)
You can set the iterations of the tree with the slider on the bottom...
Have fun with it:

Code (glbasic) Select

// --------------------------------- //
// Project: Pythagoras_Tree
// Start: Monday, July 26, 2010
// IDE Version: 7.082

TYPE tPoint
x
y
ENDTYPE

TYPE tRect
p[4] AS tPoint
ENDTYPE

TYPE tTri
p[3] AS tPoint
ENDTYPE

LOCAL p1 AS tPoint, p2 AS tPoint
p1.x=280; p1.y=425;
p2.x=380; p2.y=425;

LOCAL sx,sy
GETSCREENSIZE sx,sy

//DDGUI
DDgui_pushdialog(0,sy-30,sx,35)
DDgui_slider("slider",0,sx-12,0)
DDgui_set("slider","MINVAL",2.0)
DDgui_set("slider","MAXVAL",200.0)
DDgui_set("slider","TEXT","2.0")

LOCAL value=2


//Main loop
WHILE TRUE
DDgui_show(FALSE)
value=DDgui_get("slider","TEXT")
//DEBUG value

DrawPythagorasTree(p1,p2,value);

SHOWSCREEN
WEND

//Draw a beautiful Pythagoras Tree xD
FUNCTION DrawPythagorasTree:a AS tPoint, b AS tPoint, value
LOCAL c AS tPoint, d AS tPoint, e AS tPoint
LOCAL rect AS tRect, tri AS tTri

//Calculate the distance between Point A and B
dx% = b.x - a.x;
dy% = a.y - b.y;

//Calculate the coordinates of the Points
setPoint(c, b.x-dy%, b.y-dx%);
setPoint(d, a.x-dy%, a.y-dx%);
setPoint(e, ((c.x + d.x)/2 - (dy/2)), (c.y + d.y)/2 - (dx/2));

//one Rect and one Triangle
setPoint(rect.p[0], a.x, a.y);//rect p1
setPoint(rect.p[1], b.x, b.y);//rect p2
setPoint(rect.p[2], c.x, c.y);//rect p3
setPoint(rect.p[3], d.x, d.y);//rect p4

setPoint(tri.p[0], e.x, e.y);//tri p1
setPoint(tri.p[1], c.x, c.y);//tri p2
setPoint(tri.p[2], d.x, d.y);//tri p3

//Draw the Polygons
drawQuad(rect.p[0],rect.p[1],rect.p[2],rect.p[3]);
drawTri(tri.p[0],tri.p[1],tri.p[2]);

//Stop drawing if its crap
IF dx%*dx% + dy%*dy% > value
DrawPythagorasTree(d,e,value);
DrawPythagorasTree(e,c,value);
ENDIF
ENDFUNCTION

FUNCTION setPoint:p AS tPoint,x%,y%
p.x=x%
p.y=y%
ENDFUNCTION

FUNCTION drawQuad:p1 AS tPoint, p2 AS tPoint, p3 AS tPoint, p4 AS tPoint
STARTPOLY -1
POLYVECTOR p1.x,p1.y,p1.x,p1.y,RGB(0xff, 0xff, 0xff)
POLYVECTOR p2.x,p2.y,p2.x,p2.y,RGB(0xff, 0xff, 0xff)
POLYVECTOR p3.x,p3.y,p3.x,p3.y,RGB(0xff, 0xff, 0xff)
POLYVECTOR p4.x,p4.y,p4.x,p4.y,RGB(0xff, 0xff, 0xff)
ENDPOLY
ENDFUNCTION

FUNCTION drawTri:p1 AS tPoint, p2 AS tPoint, p3 AS tPoint
STARTPOLY -1
POLYVECTOR p1.x,p1.y,p1.x,p1.y,RGB(0xff, 0xff, 0xff)
POLYVECTOR p2.x,p2.y,p2.x,p2.y,RGB(0xff, 0xff, 0xff)
POLYVECTOR p3.x,p3.y,p3.x,p3.y,RGB(0xff, 0xff, 0xff)
ENDPOLY
ENDFUNCTION


If you want to compile, you must add the DDGui.gbas to your project or comment the ddgui-commands ;)

greets

P.S. It´s the first time I used Polyvector  :good:

[attachment deleted by admin]

Hatonastick

Mat. 5: 14 - 16

Android: Toshiba Thrive Tablet (3.2), Samsung Galaxy Tab 2 (4.1.2).
Netbook: Samsung N150+ Netbook (Win 7 32-bit + Ubuntu 11.10).
Desktop: Intel i5 Desktop with NVIDIA GeForce GTX 460 (Win 8.1 64-bit).

bigsofty

Oooh, very pretty! Well done!  =D
Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)