TWiki> CS111 Web>CS111 (2014-09-30, Main.dserge2)EditAttach
/**

* Dayanara Serges

* dserge2

* Monday 4-4:50pm

* Project 1 A Turtle Drawing

*/

import java.awt.Color;

public class dserge2Project1

{

public static void main (String[] args)

{

System.out.println("Begin Java Exection");

System.out.println("");

// put your Java Program here

Turtle t1;

Picture p1;

Turtle t2;

String infname;

infname = FileChooser.pickAFile();

// creating a new picture

p1 = new Picture(infname);

// creating turtles in the picture

t1 = new Turtle (150, 120, p1);

t2 = new Turtle (410,127, p1);

t1.setPenWidth(5);

t2.setPenWidth(5);

t1.setHeading(90);

t2.setHeading(90);

// using the drawStar method to draw stars

drawStar (t1);

t1.penUp();

t1.turn (60);

t1.forward (150);

t1.penDown();

drawStar (t1);

t1.penUp();

t1.turn (-60);

t1.forward (500);

t1.penDown();

drawStar (t1);

t1.penUp();

t1.turn (-60);

t1.forward (100);

t1.penDown();

drawStar (t1);

// using drawCircle method to draw circles

drawCircle (t2);

t2.penUp();

t2.forward (150);

t2.penDown ();

drawCircle (t2);

t1.penUp();

t1.backward (100);

t1.turn (120);

t1.backward (10);

t1.turn (120);

t1.forward (200);

t1.penDown();

// using drawTriangle method to draw Triangles

drawTriangle (t1);

t1.penUp();

t1.turn (120);

t1.backward (200);

t1.penDown();

drawTriangle (t1);

// creating multiple red triangles

int index;

index = 1;

while (index <= 3 )

{

drawTriangle (t1);

// draw another shape

t1.setPenColor (Color.RED);

t1.penUp();

t1.turn (120);

t1.forward (100);

t1.penDown();

index = index + 1;

}

t1.penUp();

t1.turn (330);

t1.forward (235);

t1.turn (300);

t1.backward (10);

t1.penDown();

// using drawHexagon to draw two hexagons

drawHexagon (t1);

index = 1;

while (index <= 2)

{

drawHexagon (t1);

// move tutle to a new position

moveTo (t1, 150, 0);

index = index + 1;

}

t1.penUp();

t1.turn (330);

t1.forward (300);

t1.penDown();

t1.backward (250);

t1.turn (90);

t1.backward (90);

t2.penUp();

t2.forward (130);

t2.turn (90);

t2.forward (170);

t2.penDown();

drawCircle (t2);

t2.penUp();

t2.turn (35);

t2.forward (200);

t2.turn (55);

t2.forward (100);

t2.penDown();

// using drawRectangle to draw rectangles

drawRectangle (t2);

index = 1;

while (index <= 2)

{

drawRectangle (t2);

// move tutle to a new position

moveTo (t2, 20, 135);

drawRectangle (t2);

moveTo (t2, -115, -50);

index = index + 1;

}

// drawing the last triangle on a rectangle

t1.setPenColor (Color.GREEN);

t1.penUp();

t1.turn (-180);

t1.forward (360);

t1.turn (90);

t1.forward (265);

t1.penDown();

drawTriangle (t1);

p1.explore();

//p1.show();

// normal code to save a picture

String outfname;

// outfname = FileChooser.pickAFile();

// p1.write ( outfname );

System.out.println("");

System.out.println("End Java Exection");

} //This is end of main

public static void moveTo (Turtle tParam, int deltaX, int deltaY)

{

System.out.println ("in moveTo, deltaX: " + deltaX + ", deltaY: " + deltaY);

tParam.penUp();

int x = tParam.getXPos();

int y = tParam.getYPos();

int movedX = x + deltaX;

int movedY = y + deltaY;

tParam.moveTo (movedX, movedY);

tParam.penDown();

}

public static void drawStar(Turtle t1)

{

int count;

count = 1;

while(count<=5)

{

t1.forward (100);

t1.turn (144);

count = count + 1;

}

}

public static void drawSquare (Turtle t2)

{

int count;

count = 1;

while(count<=4)

{

t2.forward (50);

t2.turn (90);

count = count + 1;

}

}

public static void drawTriangle (Turtle t1)

{

int count;

count = 1;

while(count<=3)

{

t1.forward (60);

t1.turn (120);

count = count + 1;

}

}

public static void drawRectangle (Turtle t2)

{

int count;

count = 1;

while(count<=4)

{

t2.forward (80);

t2.turn (90);

t2.forward (40);

t2.turn (90);

count = count + 1;

}

}

public static void drawHexagon (Turtle t1)

{

int count;

count = 1;

while(count<=6)

{

t1.forward (65);

t1.turn (60);

count = count + 1;

}

}

public static void drawCircle (Turtle t2)

{

int count = 1;

count = 1;

while (count <= 30)

{

System.out.println ("Count: " + count);

t2.forward (5);

t2.turn ( 12 );

count = count + 1;

}

}

}//End of class

Topic revision: r1 - 2014-09-30 - 03:32:49 - Main.dserge2
 
Copyright 2016 The Board of Trustees
of the University of Illinois.webmaster@cs.uic.edu
WISEST
Helping Women Faculty Advance
Funded by NSF