Results 1 to 5 of 5
- 01-11-2009, 11:51 PM #1Member
- Join Date
- Jan 2009
- Rep Power
Programming Koch's Snowflake in Java
I am in need of the starting points of how to graphically display this fractal using java... something like pseudo-Java code with steps and the formulas required to create Koch's Snowflake ... any help would be greatly appreciated! I am fairly new to Java and am using BlueJ as a compiler.
You will learn far more if you try to make an attempt at solving this yourself first, and then come back here if you hit a road block.
There are several key issues involved here, one is how to draw using Java graphics, another being how to create a recursive method since Koch's snowflake is often used as an example of a problem that can be solved by recursion (but can also be solved by non-recursive techniques).
If you do come back, your chances of getting helpful help increase with the specificity of your question. Asking broad overly general questions will get answers, well, like this one, while asking very specific questions about say an exception your code is generating will usually result in a very specific and helpful answer.
Best of luck!
- 01-12-2009, 01:07 AM #3Member
- Join Date
- Jan 2009
- Rep Power
That's the problem.. i wish i knew where to start but i'm entirely too lost .. all i have is this (most likely useless) code:
// public class KSnowflake
// public static void main (String args)
// JFrame j = new JFrame ("KSnowflake..."); // create a new window
// j.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); // stop program when we close the window
// // add a panel to the center of the content pane of the window
// j.getContentPane ().add (new KSnowflakePanel (), BorderLayout.CENTER);
// j.setSize (600, 600); // set size of the window
// j.setVisible (true); // make the window visible
public class KSnowflakeApplet extends JApplet implements MouseListener
// declare variables
int x1, x2, x3;
int y1, y2, y3;
// Constructor (setup)
public void init ()
x1 = 10;
x2 = 160;
x3 = 310;
y1 = 270;
y2 = 10;
y3 = 270;
public void paint (Graphics g)
public void Flake(int level, int x1, int y1, int x5, int y5, Graphics g)
if(level == 1)
// To fulfill our obligations as a MouseListener, we implement the following...
public void mouseClicked (MouseEvent e)
public void mouseReleased (MouseEvent e)
public void mousePressed (MouseEvent e)
public void mouseEntered (MouseEvent e)
public void mouseExited (MouseEvent e)
I wish to program it recursively, and i thought that it wouldn't be such a challenge but after reading about Koch's Snowflake on a couple of websites i became so discouraged and confused.. Recursive methods as it is confuse me since my teacher never explained the concept and did not provide us with examples as to how to use the recursive method in various math calculations in java, like for instance recursively producing the Fibonacci sequence ... i have hit a bump and i haven't even started . ok here's a more detailed question: if the level of the snowflake is NOT 1, say 2, how do i proceed to produce this recursively?
- That's the problem.. i wish i knew where to start but i'm entirely too lost
- if the level of the snowflake is NOT 1, say 2, how do i proceed to produce this recursively?
- By cserenop51 in forum NetBeansReplies: 5Last Post: 11-05-2008, 04:21 AM
- By kapil1089theking in forum AWT / SwingReplies: 8Last Post: 09-11-2008, 05:09 AM
- By gammaman in forum New To JavaReplies: 1Last Post: 12-25-2007, 02:01 AM
- By Java Tutorial in forum Java TutorialReplies: 0Last Post: 12-24-2007, 08:21 PM
- By JavaForums in forum Java TutorialReplies: 0Last Post: 07-28-2007, 11:10 PM