Sierpinski gasket...

I am trying to make a simple pgm to plot sierpinski gasket… I am using a determistic algo similar to BFS idea which utilises recurssion… I am taking first 3 mouse ip to get the intial points of the triangle…

I want to get the new set of inputs on subseqent clicks… ie 4,5,6th to be next set of data for a fresh gasket… but the prob i am facing is that since i am using recursion, and since serpinski being a fractal is an infinite loop, it is not coming out of recursion, hence i am unable to gather the next set of ips…

is there any way out of this, without going in for an iterative counterpart, coz for me recursion is pretty and beautiful…

appu

Sierpinski really isn’t a recursive process - it’s iterative. You’d probably be better using iteration for this one, and save recursion for a more appropiate task.

EDIT: Erm, if doing a random plot it’s iterative. If you’re mathematically generating the whole thing, then it is recursive, yes!

That said, you could set a limit to the number of levels deep you want it to go, but that doesn’t allow the user to interrupt the process, or to let it run indefinitely.

Maybe you could handle mouse movement and clicks inside the recursive loop, when you receive a click set the position as the first of three points, clear the screen and return. You’ll then be back at the mouse input stage waiting for the second two clicks.

[This message has been edited by cfmdobbie (edited 08-10-2003).]

actually i am using the non randomised version… have no prob with the former…

I wuld like to make my question more generic…

how does one process mouse and key strokes while inside recurssion…

is there some threading concepts etc that can be used?

appu

I think I see your problem. This is the common problem; how to actually do some processing whilst in a GUI environment. If you just go off and do your processing the whole application freezes up to the user.

You have one of two choices:

  1. Write your code so it keeps track of where the computations are and periodically release control back to the windowing system. Attach your computation to some idle function.

If you must use recursion, 1) won’t work, so you probably need to:
2) Write your computation in a separate thread. Post results occasionaly and have the opengl thread process and display the results.

why dont you have a flag set to true when the mouse clicks, then in your recursive algorithm, upon each recursion, you can check this flag.