Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / [DBP] Recursive Sierpinski Triangle

Author
Message
Neuro Fuzzy
16
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 22nd May 2010 23:19 Edited at: 22nd May 2010 23:41
Just bored. Check it out:
arrowkeys to move around, leftclick to zoom in, rightclick to zoom out.


I guess it's an alright demo of recursive functionality. It also has some useful functions for checking if something's on screen.


it uses d3dfunc lines You can remove these commands:
d3d_batch_set_line2d 100000

d3d_batch_draw_line2d 1


and replace any line that calls "d3d_batch_add_line2d" with "line", but it's very slow (dbpro built-in lines are very slow).

If you want to speed things up more, you can increase the value in this line:
if (getSiez(x1,x2,x3)+getSiez(y1,y2,y3))*PPW*camera_zoom<4.0
basically, it determines if the horizontal plus the vertical size of the triangle is less than four pixels. If it is, then it doesn't call the same function recursively.

As you zoom in a lot, the lines get jagged, and things start disappearing, and eventually the program crashes. Things get jagged because of floating point inaccuracies. Things start disappearing, probably because of rounding errors and if statements, and the program crashes probably because of a divide by zero, or passing in #inf into a function (int()?), but I haven't actually looked into either of those.

[edit]

shows floating point inaccuracies:

(You're at the edge of the map. Here be monsters)

Also, in case you're wondering why everything seems to hit a wall (speedwise) when you zoom in so close, it has to do with the way floats are processed. When a float is *almost* zero, it's very inaccurate... to account for the inaccuracies the floats are processed differently, and that's slower to process (I'm not sure why... either because the calculations are harder, or it's just not as well supported by most processors)


Neuro Fuzzy
16
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 22nd May 2010 23:20
AAAAAH I FORGOT TO PUT [DBP] tags X_X
like, the fourth time i've done that.

soooorrrrry Mr. Moderator >.>


Indicium
15
Years of Service
User Offline
Joined: 26th May 2008
Location:
Posted: 7th Jun 2010 03:12
I die after a while, and the lines just disappear, but it's pretty cool.

Rawwrr. Sig Fail.
Newcastle is awesome

Login to post a reply

Server time is: 2024-04-19 12:48:54
Your offset time is: 2024-04-19 12:48:54