In this lab were going to create some abstract art Were goin

In this lab we\'re going to create some abstract art. We\'re going to paint a digital turtle, and give him instructions for how to walk across the screen. The turtle starts at a position on the screen facing a given direction. As long as the turtle is on the screen, he leaves a footprint( draws a circle) at his current position, then walks in that direction. Sometimes he changes his direction. Write a program called Turtle that draw\'s the turtle\'s footprints using StdDraw. To start with, make the turtle zig zag by changing the y part of his direction to flip up/down every 5 steps. Your turtle should do something like the following:

Solution

public class TurtleCircle { static double x = 0; static double y = 0; static double stepsize = 1; static double direction = 0; static char[][] screen = new char[ 24 ][ 78 ]; static void turnALittle(){ direction += 10; } static void walkALittle() { final double angle = direction / 360 * 2 * java.lang.Math.PI; y = y + stepsize * java.lang.Math.sin( angle ); x = x + stepsize * java.lang.Math.cos( angle ); set( y, x ); } static { for( int i = 0; i < 24; ++i )for( int j = 0; j < 78; ++j ) screen[ i ][ j ]= \' \'; java.lang.Runtime.getRuntime().addShutdownHook ( new Thread ( new java.lang.Runnable() { public void run() { for( int i = 0; i < 24; ++i ) { for( int j = 0; j < 78; ++j ) java.lang.System.out.print( screen[ i ][ j ] ); java.lang.System.out.println(); }}})); } static void set( final double y, final double x ) { try{ screen[( int )( y + 11 )][( int )( x + 38 )]= \'*\'; } catch( final Exception e ){} } public static void main( final java.lang.String[] args ) { walkALittle(); turnALittle(); walkALittle(); turnALittle(); walkALittle(); turnALittle(); walkALittle(); turnALittle(); walkALittle(); turnALittle(); walkALittle(); turnALittle(); walkALittle(); turnALittle(); walkALittle(); turnALittle(); walkALittle(); turnALittle(); walkALittle(); turnALittle(); walkALittle(); turnALittle(); walkALittle(); turnALittle(); }}
 In this lab we\'re going to create some abstract art. We\'re going to paint a digital turtle, and give him instructions for how to walk across the screen. The

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site