Skip to content
Snippets Groups Projects
Commit 0753d1a6 authored by ABDELMOUDJIB Mohammed el amine's avatar ABDELMOUDJIB Mohammed el amine
Browse files

Upload New File

parent e4555d45
No related branches found
No related tags found
No related merge requests found
Pipeline #419 failed
import javax.swing.*;
import java.awt.*;
import java.security.PublicKey;
public class Turtle {
public Color penColor;
public double angleDirection;
public Point position;
public boolean penDown;
public Painter painter;
public Turtle(int width, int height){
penColor= null;
angleDirection=90;
painter=new Painter() {
@Override
public void paint(Graphics2D g, Object object, int width, int height) {
}
};
penDown=false;
this.position=new Point(width/2,height/2);
}
public void moveForward(double distance){
Point p=position;
Point position2=position.translate(distance*Math.cos(angleDirection),distance*Math.sin(angleDirection));
if(penDown=false){
p.drawLine(position2,painter,penColor);
}
position=position2;
}
public void setColor(Color color ){
this.penColor=color;
}
public void turnLeft(double angle){
this.angleDirection=angleDirection+angle;
}
public void turnRight(double angle){
this.angleDirection=angleDirection+angle;
}
public void setPenDown(){
this.penDown=true;
}
public void setPenUp(){
this.penDown=false;
}
void drawString(String sequence, double length, double angle){
if(sequence=="A"){
moveForward(length);
}
if(sequence=="+"){
turnRight(angle);
}
if(sequence=="-"){
turnLeft(angle);
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment