Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import se.lth.cs.ptdc.window.SimpleWindow;
- public class Turtle {
- private int x;
- private int y;
- private boolean pen;
- protected SimpleWindow w;
- private double a;
- public Turtle(SimpleWindow w, int x, int y) {
- this.x = x;
- this.y = y;
- this.w = w;
- a = Math.PI / 2;
- }
- public void penDown() {
- pen = true;
- }
- public void penUp() {
- pen = false;
- }
- public void forward(int n) {
- w.moveTo(x, y);
- x = x + (int) (Math.round(Math.cos(a) * n));
- y = y - (int) (Math.round(Math.sin(a) * n));
- if (pen) {
- w.lineTo(x, y);
- } else {
- w.moveTo(x, y);
- }
- }
- public void left(int beta) {
- a = a + Math.toRadians(beta);
- }
- public void jumpTo(int newX, int newY) {
- this.x = newX;
- this.y = newY;
- w.moveTo(newX, newY);
- }
- public void turnNorth() {
- a = Math.PI / 2;
- }
- public int getX() {
- return x;
- }
- public int getY() {
- return y;
- }
- public int getDirection() {
- return (int) Math.toDegrees(a);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement