Test #3 public static void main( String args ) Test #2 public static void main( String args ) Test #1 public static void main( String args ) The MoveBack code is below public class MoveBack extends Actionĭouble h = Math.toRadians(t.getHeading()) ĪPPoint newPoint = new APPoint(p.getX() - mySteps * Math.sin(h), Public void execute(Turtle t, Graphics g) Private ArrayList myActions = new ArrayList() įor (int i = 0 i < myActions.size() i++) The current TurtleProgram code is shown below public class TurtleProgram Define the showTurtle method of the TurtleProgram class in accordance with the above description. Where nPoints is an integer specifying the number of points (in this case, 3) that are to be joined in order to form the polygon in question, and xCoords and 圜oords are arrays of integers that specify the x- and y-coordinates, respectively, of those points. This method is overloaded, but the version that will be useful to you here has the following signature:ĭrawPolygon( int xCoords, int 圜oords, int nPoints ) If the turtle's heading is h, then you can find bottom-left by calculating where a MoveBack action of 30 turtle steps on a heading of h + 15would end up, and you can find bottom-right by calculating where a MoveBack action of 30 turtle steps on a heading of h - 15 would end up.Īrmed with these three APPoints, you can extract their x- and y-coordinates and then draw the triangle using the drawPolygon method of the Graphics object. To find the locations of the other two - let's call them bottom-left and bottom-right - you could be inspired by the execute method of the MoveBack class. ![]() The tip is easy it's just the turtle's position. ![]() You will need to calculate the locations of the three vertices of the triangle. For the sake of being specific, let's say that the apex angle will be 30 degrees and the length of each of the congruent sides of the triangle will be 30 turtle steps. ![]() The tip (or the apex) of the little triangle will be at the turtle's current position. To achieve the goal of drawing a small isosceles triangle to represent the turtle with its current position and heading, we ask you to define a new method, showTurtle in the TurtleProgram class.
0 Comments
Leave a Reply. |