package sk.paz1a.practicals.task1;
import java.awt.Color;
import sk.upjs.jpaz2.*;
public class SmartTurtle extends Turtle {
public void chain(int beadCount, double beadRadius) {
this.setFillColor(Color.blue);
this.penUp();
for (int i = 0; i < (beadCount); i++) {
this.dot(beadRadius);
this.step(2 * beadRadius);
}
}
public void ngon(int n, double sideLength) {
for (int i = 0; i < n; i++) {
this.step(sideLength);
this.turn(360.0 / n);
}
}
public void dashedLine(int n, double segmentLength) {
for (int i = 0; i < n; i++) {
this.step(segmentLength / 4);
this.penUp();
this.step(segmentLength / 2);
this.penDown();
this.step(segmentLength / 4);
}
}
public void isosceles(double legLength, double angle) {
this.turn(-angle / 2);
this.step(legLength);
double xCoord = this.getX();
double yCoord = this.getY();
this.step(-legLength);
this.turn(angle);
this.step(legLength);
this.moveTo(xCoord, yCoord);
}
public void mill(int n, int legLength) {
this.setPenColor(Color.yellow);
double xCoord = this.getX();
double yCoord = this.getY();
double direction = this.getDirection();
for (int i = 0; i < n; i++) {
this.setX(xCoord);
this.setY(yCoord);
this.setDirection(direction + i * 360 / n);
this.isosceles(legLength, 360 / (n * 2));
}
}
public void rgbChain(int beadCount, double beadRadius)
{
this.penUp();
for (int i = 0; i < (beadCount); i++) {
if (i % 3 == 0) {
this.setFillColor(Color.red);
}
if (i % 3 == 1) {
this.setFillColor(Color.green);
}
if (i % 3 == 2) {
this.setFillColor(Color.blue);
}
this.dot(beadRadius);
this.step(2 * beadRadius);
}
}
public void circleWalk(int stepCount, double radius) {
this.dot(radius);
double posx = this.getX();
double posy = this.getY();
for (int i = 0; i < stepCount; i++) {
this.turn(Math.random() * 360);
this.step(5);
if (this.distanceTo(posx, posy) >= radius) {
this.step(-5);
}
}
this.setPosition(posx, posy);
}
public void squareWalk(int stepCount, double sideLength) {
double posx = this.getX();
double posy = this.getY();
for (int i = 0; i < stepCount; i++) {
this.turn(Math.random() * 360);
this.step(5);
if (this.getX() >= posx + sideLength / 2) {
this.step(-5);
}
if (this.getY() >= posy + sideLength / 2) {
this.step(-5);
}
if (this.getY()<= posy - sideLength/2) {
this.step(-5);
}
if (this.getX() <= posx - sideLength / 2) {
this.step(-5);
}
}
this.setPosition(posx, posy);
}
}