Results 1 to 2 of 2
Thread: For Loop Help
- 10-04-2010, 05:55 PM #1
Member
- Join Date
- Sep 2010
- Posts
- 60
- Rep Power
- 0
For Loop Help
Hey I have made a koch curve below. I have a huge code which can be shortened to a for loop. Can someone help me make it into a for loop. Thanks
Java Code:package lab_5; import javax.swing.*; import java.awt.*; public class TurtleDriver extends JPanel { JFrame frame; public TurtleDriver() { super(); frame = new JFrame("Testing the Turtle"); frame.setSize(600, 600); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(this); frame.setVisible(true); this.setBackground(Color.white); } public void paintComponent(Graphics g) { Graphics2D graphics = (Graphics2D)g; int x0 = this.getX(); int y0 = this.getY(); int width = this.getWidth(); int height = this.getHeight(); Turtle turtle = new Turtle(frame, graphics, x0, y0, width, height); turtle.moveTo(0.3, .8, 0.0); turtle.spiraMirabilis(60.0,0.001,1.09); turtle.moveTo(0.6, .8, 0.0); turtle.spiraMirabilis(75.0,0.001,1.09); //Three Sides turtle.moveTo(0.1, 0.1, 0.0); turtle.koch(0.1,3); turtle.turnLeft(-120); turtle.koch(0.1,3); turtle.turnLeft(-120); turtle.koch(0.1,3); // Regular polygon with 4 sides turtle.moveTo(0.3, 0.15, 0.0); turtle.koch(0.1,3); turtle.turnLeft(-90); turtle.koch(0.1,3); turtle.turnLeft(-90); turtle.koch(0.1,3); turtle.turnLeft(-90); turtle.koch(0.1,3); turtle.turnLeft(-90); turtle.koch(0.1,3); // Regular polygon with 5 sides turtle.moveTo(0.5, 0.18, 0.0); turtle.koch(0.1,3); turtle.turnLeft(-72); turtle.koch(0.1,3); turtle.turnLeft(-72); turtle.koch(0.1,3); turtle.turnLeft(-72); turtle.koch(0.1,3); turtle.turnLeft(-72); turtle.koch(0.1,3); turtle.turnLeft(-72); turtle.koch(0.1,3); //regular polygon with 6 sides turtle.moveTo(0.7, 0.22, 0.0); turtle.koch(0.1,3); turtle.turnLeft(-60); turtle.koch(0.1,3); turtle.turnLeft(-60); turtle.koch(0.1,3); turtle.turnLeft(-60); turtle.koch(0.1,3); turtle.turnLeft(-60); turtle.koch(0.1,3); turtle.turnLeft(-60); turtle.koch(0.1,3); turtle.turnLeft(-60); turtle.koch(0.1,3); //polygon with 7 sides turtle.moveTo(0.7, 0.5, 0.0); turtle.koch(0.1,3); turtle.turnLeft(-51.428571429); turtle.koch(0.1,3); turtle.turnLeft(-51.428571429); turtle.koch(0.1,3); turtle.turnLeft(-51.428571429); turtle.koch(0.1,3); turtle.turnLeft(-51.428571429); turtle.koch(0.1,3); turtle.turnLeft(-51.428571429); turtle.koch(0.1,3); turtle.turnLeft(-51.428571429); turtle.koch(0.1,3); turtle.turnLeft(-51.428571429); turtle.koch(0.1,3); //polygon with 8 sides turtle.moveTo(0.3, 0.5, 0.0); turtle.koch(0.1,3); turtle.turnLeft(-45); turtle.koch(0.1,3); turtle.turnLeft(-45); turtle.koch(0.1,3); turtle.turnLeft(-45); turtle.koch(0.1,3); turtle.turnLeft(-45); turtle.koch(0.1,3); turtle.turnLeft(-45); turtle.koch(0.1,3); turtle.turnLeft(-45); turtle.koch(0.1,3); turtle.turnLeft(-45); turtle.koch(0.1,3); turtle.turnLeft(-45); turtle.koch(0.1,3); } public static void main(String[] args) { new TurtleDriver(); } }
- 10-04-2010, 06:02 PM #2
Similar Threads
-
Help with loop
By Scatty in forum New To JavaReplies: 4Last Post: 05-18-2010, 07:23 AM -
How can I rewrite the following while loop using a for loop?
By gt11990 in forum New To JavaReplies: 5Last Post: 04-30-2010, 05:05 PM -
do while loop?
By shroomiin in forum New To JavaReplies: 2Last Post: 11-13-2009, 10:32 AM -
while-loop stopping on first loop
By davester in forum New To JavaReplies: 6Last Post: 06-26-2009, 08:46 PM -
while loop help
By kathyla18 in forum New To JavaReplies: 1Last Post: 03-02-2009, 06:49 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks