Skip to content

Instantly share code, notes, and snippets.

@juliosandino
Last active September 26, 2016 18:40
Show Gist options
  • Save juliosandino/af00e90c235520623c3293fa9b5a6b10 to your computer and use it in GitHub Desktop.
Save juliosandino/af00e90c235520623c3293fa9b5a6b10 to your computer and use it in GitHub Desktop.
First Assignment for CS11 @ UC SAN Diego
package sandino.julio;
import turtleClasses.ModelDisplay;
import turtleClasses.Turtle;
import turtleClasses.World;
import java.awt.*;
public class Main extends Turtle{
//RULE FOR THE CODE!!!
//After Each letter finishes, The turtle must end at right side of the letter.
//After Each letter finishes, the pen must be up.
//This is done so that the spacing works correctly and the new line function works as well.
static final int WINDOW_HEIGHT = 480;
static final int WINDOW_WIDTH = 1080;
static final int STARTING_X = 40;
static final int STARTING_Y = 40;
static final int LETTER_HEIGHT = 80;
static final int LETTER_WIDTH = 40;
static final int STROKE_WIDTH = 8;
static final int SPACE = 40;
public Main(ModelDisplay modelDisplay) {
super(modelDisplay);
}
public static void main(String args[]){
World world = new World(WINDOW_WIDTH, WINDOW_HEIGHT);
Main turtle = new Main(world);
turtle.setPenColor(Color.blue);
turtle.setPenWidth(STROKE_WIDTH);
turtle.penUp();
turtle.moveTo(STARTING_X, STARTING_Y);
//first line
turtle.drawC();
turtle.spaceOne();
turtle.drawS();
turtle.spaceOne();
turtle.draw1();
turtle.spaceOne();
turtle.draw1();
turtle.spaceOne();
turtle.drawF();
turtle.newline();
//second line
turtle.drawJ();
turtle.spaceTwo();
turtle.drawA();
turtle.spaceTwo();
turtle.drawV();
turtle.spaceTwo();
turtle.drawA();
turtle.spaceTwo();
turtle.spaceTwo();
turtle.spaceTwo();
turtle.draw2();
turtle.spaceTwo();
turtle.draw0();
turtle.spaceTwo();
turtle.draw1();
turtle.spaceTwo();
turtle.draw6();
turtle.newline();
//third line
turtle.drawU();
turtle.spaceThree();
turtle.drawC();
turtle.spaceThree();
turtle.spaceThree();
turtle.spaceThree();
turtle.drawS();
turtle.spaceThree();
turtle.drawA();
turtle.spaceThree();
turtle.drawN();
turtle.spaceThree();
turtle.spaceThree();
turtle.spaceThree();
turtle.drawD();
turtle.spaceThree();
turtle.drawI();
turtle.spaceThree();
turtle.drawE();
turtle.spaceThree();
turtle.drawG();
turtle.spaceThree();
turtle.draw0();
}
void drawU(){
penUp();
turnToFace(getXPos(), getYPos() + 1);
penDown();
forward(LETTER_HEIGHT);
penUp();
turnLeft();
penDown();
forward(LETTER_WIDTH);
penUp();
turnLeft();
penDown();
forward(LETTER_HEIGHT);
penUp();
}
public void drawC(){
turnToFace(getXPos() + 1, getYPos());
penDown();
forward(LETTER_WIDTH);
penUp();
turnBack();
forward(LETTER_WIDTH);
turnLeft();
penDown();
forward(LETTER_HEIGHT);
penUp();
turnLeft();
penDown();
forward(LETTER_WIDTH);
penUp();
}
public void drawS(){
turnToFace(getXPos() + 1, getYPos());
penDown();
forward(LETTER_WIDTH);
penUp();
turnBack();
forward(LETTER_WIDTH);
turnLeft();
penDown();
forward(LETTER_HEIGHT / 2);
turnLeft();
forward(LETTER_WIDTH);
turnRight();
forward(LETTER_HEIGHT / 2);
turnRight();
forward(LETTER_WIDTH);
penUp();
turnBack();
forward(LETTER_WIDTH);
}
public void drawF(){
turnToFace(getXPos() + 1, getYPos());
penDown();
forward(LETTER_WIDTH);
turnBack();
forward(LETTER_WIDTH);
turnLeft();
forward(LETTER_HEIGHT / 2);
turnLeft();
forward(2 * LETTER_WIDTH / 3);
turnBack();
forward(2 * LETTER_WIDTH / 3);
turnLeft();
forward(LETTER_HEIGHT / 2);
turnLeft();
penUp();
forward(LETTER_WIDTH);
}
public void drawJ(){
turnToFace(getXPos() + 1, getYPos());
penDown();
forward(LETTER_WIDTH);
backward(LETTER_WIDTH / 2);
turnRight();
forward(LETTER_HEIGHT);
turnRight();
forward(LETTER_WIDTH / 2);
turnRight();
forward(LETTER_HEIGHT / 5);
penUp();
backward(LETTER_HEIGHT / 5);
turnRight();
forward(LETTER_WIDTH);
}
public void drawA(){
int XendPosition;
int YendPosition;
turnToFace(getXPos(), getYPos() + 1);
forward(LETTER_HEIGHT);
turnBack();
turn(15);
penDown();
forward(LETTER_HEIGHT);
turn(150);
forward(LETTER_HEIGHT);
XendPosition = getXPos();
YendPosition = getYPos();
turnBack();
forward(LETTER_HEIGHT / 2);
turnToFace(getXPos() - 1, getYPos());
forward(LETTER_WIDTH / 2);
penUp();
moveTo(XendPosition, YendPosition);
}
public void drawV(){
turnToFace(getXPos(), getYPos() + 1);
turn(-15);
penDown();
forward(LETTER_HEIGHT);
turn(-150);
forward(LETTER_HEIGHT);
penUp();
turnToFace(getXPos(), getYPos() + 1);
forward(LETTER_HEIGHT);
}
public void drawN(){
turnToFace(getXPos(), getYPos() + 1);
penDown();
forward(LETTER_HEIGHT);
backward(LETTER_HEIGHT);
turn(-30);
forward((int) (LETTER_HEIGHT / Math.cos(Math.PI / 6)));
turn(-150);
forward(LETTER_HEIGHT);
penUp();
backward(LETTER_HEIGHT);
}
public void drawD(){
turnToFace(getXPos(), getYPos() + 1);
penDown();
forward(LETTER_HEIGHT);
turnLeft();
forward(LETTER_WIDTH);
turn(-60);
forward(LETTER_HEIGHT / 3);
turn(-30);
forward(LETTER_HEIGHT / 2);
turn(-30);
forward(LETTER_HEIGHT / 3);
turn(-60);
forward(LETTER_WIDTH);
penUp();
backward(LETTER_WIDTH);
turnLeft();
forward(LETTER_HEIGHT);
}
public void drawI(){
turnToFace(getXPos() + 1, getYPos());
penDown();
forward(LETTER_WIDTH);
backward(LETTER_WIDTH / 2);
turnRight();
forward(LETTER_HEIGHT);
turnLeft();
backward(LETTER_WIDTH / 2);
forward(LETTER_WIDTH);
penUp();
}
public void drawE(){
turnToFace(getXPos() + 1, getYPos());
penDown();
forward(LETTER_WIDTH);
backward(LETTER_WIDTH);
turnRight();
forward(LETTER_HEIGHT / 2);
turnLeft();
forward(LETTER_WIDTH);
backward(LETTER_WIDTH);
turnRight();
forward(LETTER_HEIGHT / 2);
turnLeft();
forward(LETTER_WIDTH);
penUp();
}
public void drawG(){
int XendPosition;
int YendPosition;
turnToFace(getXPos() + 1, getYPos());
penDown();
forward(LETTER_WIDTH);
backward(LETTER_WIDTH);
turnRight();
forward(LETTER_HEIGHT);
turnLeft();
forward(LETTER_WIDTH);
XendPosition = getXPos();
YendPosition = getYPos();
turnLeft();
forward(LETTER_HEIGHT / 2);
turnLeft();
forward(LETTER_WIDTH / 5);
penUp();
moveTo(XendPosition, YendPosition);
}
public void draw0(){
int XendPosition;
int YendPosition;
turnToFace(getXPos() + 1, getYPos());
penDown();
forward(LETTER_WIDTH);
turnRight();
forward(LETTER_HEIGHT);
XendPosition = getXPos();
YendPosition = getYPos();
turnRight();
forward(LETTER_WIDTH);
turnRight();
forward(LETTER_HEIGHT);
penUp();
moveTo(XendPosition, YendPosition);
}
public void draw1(){
moveTo(getXPos() + LETTER_WIDTH / 2, getYPos());
turnToFace(getXPos(), getYPos() + 1);
turn(45);
penDown();
forward(LETTER_WIDTH / 4);
turnBack();
penUp();
forward(LETTER_WIDTH / 4);
turnToFace(getXPos(), getYPos() + 1);
penDown();
forward(LETTER_HEIGHT);
penUp();
turnRight();
forward(LETTER_WIDTH / 2);
turnBack();
penDown();
forward(LETTER_WIDTH);
penUp();
}
public void draw2(){
turnToFace(getXPos() + 1, getYPos());
penDown();
forward(LETTER_WIDTH);
turnRight();
forward(LETTER_HEIGHT / 2);
turnRight();
forward(LETTER_WIDTH);
turnLeft();
forward(LETTER_HEIGHT / 2);
turnLeft();
forward(LETTER_WIDTH);
penUp();
}
public void draw6(){
int XendPosition;
int YendPosition;
turnToFace(getXPos() + 1, getYPos());
penDown();
forward(LETTER_WIDTH);
backward(LETTER_WIDTH);
turnRight();
forward(LETTER_HEIGHT);
turnLeft();
forward(LETTER_WIDTH);
XendPosition = getXPos();
YendPosition = getYPos();
turnLeft();
forward(LETTER_HEIGHT / 2);
turnLeft();
forward(LETTER_WIDTH);
penUp();
moveTo(XendPosition, YendPosition);
}
public void spaceOne(){
moveTo(getXPos() + SPACE, STARTING_Y);
}
public void spaceTwo(){
moveTo(getXPos() + SPACE, STARTING_Y + LETTER_HEIGHT + SPACE);
}
public void spaceThree(){
moveTo(getXPos() + SPACE, STARTING_Y + 2 * (LETTER_HEIGHT + SPACE));
}
public void newline(){
moveTo(STARTING_X, getYPos() + SPACE);
}
public void turnBack(){
turnLeft();
turnLeft();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment