aspose file tools*
The moose likes Beginning Java and the fly likes Recursion SnowFlake ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Recursion SnowFlake ?" Watch "Recursion SnowFlake ?" New topic
Author

Recursion SnowFlake ?

Shananne DuFrame
Ranch Hand

Joined: Nov 13, 2006
Posts: 51
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.

Heres the code so far:
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
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.

Good luck!

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 ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60049
    
  65

"pete stn",

There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
JavaRanch Sheriff


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
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.
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
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 ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60049
    
  65

Originally posted by pete stein:

So adjusted... It's just that using my real name has gone against everything i've ever been previously taught about online security.


Then don't use it. Just don't use something that's obviously fictitious like "stn".
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
On trial, I may have gotten my order of points backwards. If so, consider trying this:

Shananne DuFrame
Ranch Hand

Joined: Nov 13, 2006
Posts: 51
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!!

Thanks again,
Shananne
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
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 ]
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
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.


"I'm not back." - Bill Harding, Twister
Shananne DuFrame
Ranch Hand

Joined: Nov 13, 2006
Posts: 51


Heres the working program..and again thanks alot!!
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Recursion SnowFlake ?
 
Similar Threads
quadruple
Funny JavaScripts
Koch SnowFlake
when static variables are initialized
Scrollbar not working