From 0753d1a6cdebb719ea3b1f3a656eb89c4c6af418 Mon Sep 17 00:00:00 2001 From: ABDELMOUDJIB Mohammed el amine <mohammed-el-amine.abdelmoudjib@etu.univ-amu.fr> Date: Mon, 23 Nov 2020 00:05:05 +0100 Subject: [PATCH] Upload New File --- tp6/Turtle.java | 65 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 tp6/Turtle.java diff --git a/tp6/Turtle.java b/tp6/Turtle.java new file mode 100644 index 0000000..b522461 --- /dev/null +++ b/tp6/Turtle.java @@ -0,0 +1,65 @@ +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); + } + + } + +} -- GitLab