Midterm exam 1 review Sp2005: Turtle Initial
Comments? Questions? Answers? Questions on Answers? Comments on Answers?
I'm rusty with the turtles.
public class TurtleInitial {
public static void main(String [] args){
// set variables
Picture canvas = new Picture(600,600);
Turtle hdraw = new Turtle(canvas);
// draw h
hdraw.forward(200);
hdraw.turn(90);
hdraw.forward(200);
hdraw.turn(180);
hdraw.forward(400);
hdraw.turn(180);
hdraw.forward(200);
hdraw.turn(90);
hdraw.forward(200);
hdraw.turn(90);
hdraw.forward(200);
hdraw.turn(180);
hdraw.forward(400);
//show canvas
canvas.show();
}
}
Student36
Anybody got an initial that might involve a LOOP(iteration? while? for?)? Mark Guzdial |
An "M" could work well for this
no clue how the loops work on this.
also, none of my turtle stuff works...it makes me open previous java files until it hits a private one that i can't find to compile...
my turtle stuff doesn't work either. my classpath is correct and stuff is complied correctly.
Okay, for the first person: You do have to open and then Compile All for about five files. (Corali went through them yesterday, and that's about how many it took her.) For the second questioner: What "doesn't work"? If you let me know the error message, I can try to figure out why your turtle stuff doesn't work. Note: It will HAVE to work for Homework 6 and maybe Homework 5 (depending on how you do it), so it's worth figuring it out. Mark Guzdial |
just draw the initial or make it drop a pic while drawing our initial?
public class MyTurtlePicture {
public static void main(String [] args) {
//My last initial "p"
FileChooser.setMediaPath("C:/CS1316/MediaSources/");
Picture canvas = new Picture(800,800);
Turtle jenny = new Turtle(canvas);
Picture lilT = new Picture(FileChooser.getMediaPath("Turtle.jpg"));
//draw straight line going down for the stem of "P"
for (int i =0; i <=10; i++)
{
jenny.forward(25);
jenny.drop(lilT.scale(0.5));
}
//loop of the "p"
for (int i=0; i <=10; i++)
{
if (i ==0)
{jenny.turn(75);}
else
{jenny.turn(19);}
jenny.forward(30);
jenny.drop(lilT.scale(0.5));
}
canvas.show();
}
}
Student48
public class MyTurtlePicture {
public static void main(String [] args) {
FileChooser.setMediaPath("C:/Documents and Settings/Owner/My Documents/School/1.2/CS1316/MediaSources/");
Picture canvas = new Picture(600,600);
Turtle jenny = new Turtle(canvas);
Picture lilTurtle = new Picture(FileChooser.getMediaPath("Turtle.jpg"));
jenny.turn(180);
jenny.forward(190);
jenny.turn(-90);
for (int i=0; i <=32; i++)
{jenny.turn(-5);
jenny.forward(5);
};
jenny.turn(150);
for (int i=0; i <=30; i++)
{jenny.turn(-5);
jenny.forward(5);
};
jenny.drop(lilTurtle.scale(0.5));
canvas.show();
}
}
okay, but i would never have gotten it if i didn't fiddle with it in dr. java. this is bad, yes?
Think about why you have in there what you have in there. Only include the things you need. There's no need to drop a picture, just to make your initial. Mark Guzdial |
i know why i have what i have. my problem is getting the numbers right. the turns and the forwards in order to make sure the letter isn't deformed on the curved parts.
i.e. the 5's on the last one posted
Link to this Page