4 Sided Shape drawing function
Re: 4 Sided Shape drawing function
I figured there must be a way to perform the function using allocated memory, but I just made all the variables that I use in the function to a struct and then just push that around to go around my problem.
I managed to get it fill about 3/4 of my screen, but then I still get overflow : -/
I managed to get it fill about 3/4 of my screen, but then I still get overflow : -/
ʕ •ᴥ•ʔ
Re: 4 Sided Shape drawing function
I don't know, didn't look up the algorithm directly. I just watched the example of flood fill on wikipedia and snapped my fingers and did it all by my self : -D
http://upload.wikimedia.org/wikipedia/c ... aka%29.gif
Basically a function that draws at four points and uses itself again untill it cant be called again...
http://upload.wikimedia.org/wikipedia/c ... aka%29.gif
Basically a function that draws at four points and uses itself again untill it cant be called again...
ʕ •ᴥ•ʔ
Re: 4 Sided Shape drawing function
I guess I could try to make that right hand fill method, looks a tad faster and doesn't root in the function too deeply.
ʕ •ᴥ•ʔ
Re: 4 Sided Shape drawing function
Hi Lux,
I wouldn't have thought you could put a function on the heap, but I imagine you could load all your nodes or cooridnates into a memory location which could be on a heap.
Asimov
I wouldn't have thought you could put a function on the heap, but I imagine you could load all your nodes or cooridnates into a memory location which could be on a heap.
Asimov
----> Asimov
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk
Re: 4 Sided Shape drawing function
Even if you did that, you would still be using stack memory. Every time you call a function, at the very least the return address for that call is pushed onto the stack. In addition, only local variable for the function are also pushed (this includes the function parameters). The only real solution is to change your algorithm to reduce the depth of recursion, or better yet, convert the recursion into a loop. You can also simulate recursion in a loop by creating your own stack on the heap. In that case you can make it as big as you like.
Chili
Re: 4 Sided Shape drawing function
Hi Chilli,
Could you explain recursion. It sounds like a loop within a loop or something,
Or it sounds VERY bad LOL.
Asimov
Could you explain recursion. It sounds like a loop within a loop or something,
Or it sounds VERY bad LOL.
Asimov
----> Asimov
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk
Re: 4 Sided Shape drawing function
Simple, You have four points like a "+" for each four points you check if the bottom pixel is equal to sample pixel you want to fill, if it is, fill it and spawn a new "+" there. Basically it will go on until it cant find new points to spawn at.
Each new color is a new node being drawn at all four points of the original red one, as best as they can be. Obviously they would also spawn more nodes on each point, but for this example, its one (red) node performing all its roots.
There might be a better way to direct the spawning, so it wouldn't root down too badly, that's the problem I'm having. Chili said we will be going over something like this eventually. Or maybe another way where we scan lines. I tried to look that up, but all the videos on youtube were some Indian professors.... The accent...
Each new color is a new node being drawn at all four points of the original red one, as best as they can be. Obviously they would also spawn more nodes on each point, but for this example, its one (red) node performing all its roots.
There might be a better way to direct the spawning, so it wouldn't root down too badly, that's the problem I'm having. Chili said we will be going over something like this eventually. Or maybe another way where we scan lines. I tried to look that up, but all the videos on youtube were some Indian professors.... The accent...
ʕ •ᴥ•ʔ
Re: 4 Sided Shape drawing function
To sum up what recursion is, it is basicly a function that can call itself, for exampleAsimov wrote:Hi Chilli,
Could you explain recursion. It sounds like a loop within a loop or something,
Or it sounds VERY bad LOL.
Asimov
Code: Select all
# include<stdio.h>
int factorial(unsigned int number)
{
if(number <= 1)
return 1;
return number * factorial(number - 1);
}
void main()
{
int x = 5;
printf("factorial of %d is %d",x,factorial(x));
MOOOOOO
Re: 4 Sided Shape drawing function
Hi codinitup,
Ah thank you. So it is like the Mr No where man in the yellow submarine swallowing himself.
To be honest I think there could be better ways of writing the same routine without using recursion. Recursion sounds too much like a forever goto loop for my liking LOL, with a nasty break; command to get out of the loop heh heh.
Asimov
Ah thank you. So it is like the Mr No where man in the yellow submarine swallowing himself.
To be honest I think there could be better ways of writing the same routine without using recursion. Recursion sounds too much like a forever goto loop for my liking LOL, with a nasty break; command to get out of the loop heh heh.
Asimov
----> Asimov
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk