Results 1 to 2 of 2
  1. #1
    darkzboy is offline Member
    Join Date
    Oct 2013
    Posts
    1
    Rep Power
    0

    Default Epitrochoid using Turtle Graphics?

    Link to question: Fundamentals of Computer Science Using Java - David Hughes - Google Books
    Question 42.

    How would one get started on this? I've looked at all my examples from my labs and cannot seem to figure this one out for the life of me, I've even asked a couple of people in the course on facebook, and they all just tell me to 'skip the question'.

    I figured I start by figuring out the code for the inner loop and the outer loop.. but its still not working.

    Can anyone please help?

    Java Code:
    package Epitrochoid;
    
    import Media.*; // for displayer and turtle 
    import java.awt.*; // for Color class
    import static java.lang.Math.*; // for math constants, functions & random 
    import static Media.Turtle.*; // for turtle speed constants 
    import static java.awt.Color.*; // for Color constants 
    
    public class Epitrochoid {
      private TurtleDisplayer display; // display to draw on
      private Turtle          yertle; // turtle to do drawing
     // Instance variable declarations 
      
     public Epitrochoid ( ) {
       display = new TurtleDisplayer();
       yertle = new Turtle(Turtle.FAST);
       display.placeTurtle(yertle);
       
       yertle.penDown();
       drawEpitrochoid();
      }; // constructor 
     
     
     private void drawEpitrochoid ( double a, double b, double k, int num ) {
       double x; //x-coordinate
       double y; //y-coordinate(y= f(x))
       int t;
       
       
       yertle.right(angle);
       yertle.forward(radius);
       
       for ( t=1 ; t<=num ; t++ ) {
          t = 1/num;
          x = (a+b)*cos(2*PI*t) - k * cos(2*PI*(a+b)*(t/b));
          y = (a+b)*sin(2*PI*t) - k * sin(2*PI*(a+b)*(t/b));
           yertle.moveTo(x,y);
       };
    
    }; // drawEpitrochoid
     
    
     
     
     
     
     public static void main ( String[] args ) { Epitrochoid v = new Epitrochoid(); }; 
    }
    Last edited by darkzboy; 10-27-2013 at 08:02 PM.

  2. #2
    Quan is offline Member
    Join Date
    Oct 2013
    Posts
    1
    Rep Power
    0

    Default Re: Epitrochoid using Turtle Graphics?

    Random question... do you attend Brock?

    EDIT: Actually, that was a dumb question, just saw the "David Hughes" bit... you're practicing for the lab test, yes?
    (just curious because I am doing the same thing...*cough*)

    EDIT 2: off the top of my head, should you not be initializing a, b etc in the public class?
    e.g double a = 50;
    double b = etc.

    yertle.penDown();
    drawEpitrochoid( a, b, k, num);
    Last edited by Quan; 10-27-2013 at 11:00 PM.

Similar Threads

  1. turtle graphics
    By Kareem Mesbah in forum New To Java
    Replies: 1
    Last Post: 10-20-2012, 08:15 PM
  2. Replies: 1
    Last Post: 12-09-2011, 01:18 PM
  3. Downloading Turtle Graphics and Other Packages
    By Godsarmy4vr2 in forum New To Java
    Replies: 4
    Last Post: 02-28-2010, 06:19 PM
  4. Turtle assignment
    By jmc724 in forum New To Java
    Replies: 11
    Last Post: 07-16-2008, 09:11 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •