#Help with Barnsley Fern (raylib)

10 messages · Page 1 of 1 (latest)

crimson lynx
#

I created a Barnsley Fern with raylib but, while it runs without errors, the output does not look like the picture of the fern on Wikipedia. The leaves just look too narrow instead of being full like the fern is supposed to be. I already double checked that I'm using the correct coefficients, so that is not the issue.

#

One second...

#

This is what my code outputs, as you can see each leaf is really narrow for some reason.

#

I want to also explain my reasoning for:

float screenX = ((x + 2.5) * (screenWidth / 5.0));
float screenY = screenHeight - y * (screenHeight / 10.0);

The x and y calculated by the equations are quite small. X tends to be between -2.5 and 2.5, and y tends to be between 0 and 10. So here I am scaling by the screen's width and height, and translating X (to be non zero values).

#

Also, you can change the screenWidth and screenHeight but it does not solve the problem of the leaves being too narrow.

remote tapir
#

Why are you dividing by 5 and 10 respectively? The code looks mostly correct so I'd guess you might have to play around with your scaling to get something that looks a bit nicer.

Cool to see people using Raylib though, I think I'll try to get your code running when I'm back home - maybe I can find a nice scaling factor.

crimson lynx
#

@remote tapir That's to scale it by the range of the x and y values. X is usually between -2.5 and 2.5 so it's a range of 5. But now that you mention it, I'm now getting confused thinking about this and think I might have reasoned that incorrectly? would you mind helping me figure out what is the correct way to scale it if that's wrong?
I'm gonna play around with that part more now too..

#

Thanks so much for taking a look btw.

#

Actually I think that scaling is correct, because I'm multipling by the ratio between the x (or y) range and the screen's range, in order to scale it up