I have this assignment I've been working on. We are to try and imitate the Koch Snowflake...The teacher knows that there are many other resolves for this on the net but she would like us to try our own, without using one from the net. I have gotten as far as to get one side of the snowflake to work. For instance if I enter a level of 1 of recusion it only draws the bottom line of the triangle. If I enter level 3 it draws what looks to be the snowflake but only on the bottom. This is the code I have done to get to this point. Any hints or clues to the right direction to get the same desing to rotate the full 360 would be great.
Just on first glance, your calculations for x3 and y3 should work great for when the baseline that the flake is growing on is horizontal, but I don't think this is going to work when you create higher order iterations of the snowflake upon higher order baselines that are not horizontal. I think that you'll need fancier math calculations, but please take this with a grain of salt as I'm no mathematician and no computer scientist.
Instead of setting up your equations looking at the first iteration w/ a flat baseline, try setting up your equations for the general case where the baseline is angled and you'll see what I mean. There are probably several ways to come up w/ functioning equations, probably the easiest will be to use some trig.
Correction: Sorry, I'm messing up. I ran through your equations and they all look fine. I guess I'm rusty on my trig. Again, sorry. [ February 26, 2007: Message edited by: pete stein ]
Originally posted by Bear Bibeault: "pete stn", In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious. ... JavaRanch Sheriff
So adjusted... It's just that using my real name has gone against everything i've ever been previously taught about online security.
perhaps what you need to do is set up your equilateral triangle as the starting 3 points of your snowflake. You also might want to consider doing your calcs using double then either cast to int or round to int for your display routine.
Something like this:
Let me know if any of this helps.
/Pete [ February 26, 2007: Message edited by: pete stein ]
Thank you very much pete. I used the first code you had posted along with what I originally had and changed a few things. As you had stated lastly the code prior had developed a different snow flake than what was being required. But looking at your code helped me realize what I needed to do and what was missing. I now have a working program!!
Originally posted by Shananne DuFrame: .. I now have a working program!!
Cool! Let's see the code when you're finished if you don't mind. I don't know much java-graphics yet, but I used your code (thanks) to make a snowflake program in c#, and showed it to my daughter who was quite impressed. Since she's a 12 year old, that's saying a lot! I'll have to try the Mandelbrot set next. /Pete [ February 27, 2007: Message edited by: pete steinbear ]
Ahhh... "Steinbear" looks a little too artificial, especially under the circumstances. How about something that has a chance of appearing in a real-world phonebook? Like, say, Steinman, or Stanley, or Mullins, or whatever. Crack open a phonebook if you need ideas. Not something that sounds like a made-up hybrid. Thanks.
Looks good! I'm kind of a newbie in java as I've been doing most of my previous coding in c#. So, sorry for what's probably a simple question, but how do you call this class to display it? Thanks /Pete
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop