| | |
recursion problem...
Thread Solved |
•
•
Join Date: May 2006
Posts: 17
Reputation:
Solved Threads: 0
I am trying to write a recursive function that will produce a fractal snowflake, but am not getting the correct results. For some reason it gets caught in an infinte loop, but I cannot figure out why. Any help is appreciated.
private void recursiveDraw(double x1, double y1, double x2, double y2, int orderNum, Graphics gr) { if (orderNum == 0) { gr.drawLine((int) x1, (int) y1, (int) x2, (int) y2); } else { double x4 = x1 * 2 / 3 + x2 * 1 / 3; double y4 = y1 * 2 / 3 + y2 * 1 / 3; double x5 = x1 * 1 / 3 + x2 * 2 / 3; double y5 = y1 * 1 / 3 + y2 * 2 / 3; double x6 = (x4 + x5) / 2 + (y4 - y5) * sqrt(3) / 2; double y6 = (y4 + y5) / 2 + (x5 - x4) * sqrt(3) / 2; recursiveDraw(x1, y1, x4, y4, orderNum, gr); recursiveDraw(x4, y4, x6, y6, orderNum, gr); recursiveDraw(x6, y6, x5, y5, orderNum, gr); recursiveDraw(x5, y5, x2, y2, orderNum, gr); } }
![]() |
Similar Threads
- help with recursion (C++)
- how do you reverse a linked list using recursion and return it as a string? (Java)
- recursion problem (C)
- help with recursion (C)
- C++ Beginner - #include recursion problem (C++)
Other Threads in the Java Forum
- Previous Thread: Problem in installing JOnASJOnAs 4.8.4-tomcat5.5.17
- Next Thread: call a method in an object, by giving the same object as the parameter
| Thread Tools | Search this Thread |
android api applet application apps array arrays automation awt bidirectional binary birt bluetooth businessintelligence busy_handler(null) card class classes client code collision columns component constructor database designadrawingapplicationusingjavajslider draw eclipse error errors eventlistener exception expand fractal free game givemetehcodez graphics gui guidancer html ide image inetaddress integer integration intellij j2me java javafx javamicroeditionuseofmotionsensor javaprojects jme jni jpanel jtree julia linux list loop machine map method methods migrate mobile mobiledevelopmentcreatejar myaggfun netbeans newbie oracle plazmic print problem program programming project radio recursion scanner server set sharepoint smart sms smsspam sort sortedmaps sql string subclass support swing textfield threads tree unlimited utility webservices windows






