package sk.paz1a.practicals.task2;
import java.awt.Color;
import sk.upjs.jpaz2.*;
public class SmartTurtle extends Turtle {
public void chain(int beadCount, double beadRadius) {
this.setFillColor(Color.blue);
for (int i = 0; i < beadCount; i++) {
this.dot(beadRadius);
this.penUp();
this.step(2 * beadRadius);
this.penDown();
}
}
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) {
// Do premennych startX a startY si ulozime
// poziciu korytnacky pri zavolani tejto metody
double startX = this.getX();
double startY = this.getY();
// Do premennej natocenie si ulozime natocenie (smer)
// korytnacky pri zavolani tejto metody
double direction = this.getDirection();
// Kreslenie
this.turn(-angle / 2);
this.step(legLength);
// Sme v bode A, ulozime si teda x-ovu a y-ovu suradnicu
// tohto bodu (pouzijeme ich neskor)
// Vytvorime premennu xCoord na hodnoty typu double
double xCoord;
// Do premennej xCoord ulozime aktualnu x-ovu suradnicu
// pozicie korytnacky - ziskame ju tak, ze sa "sami seba" spytame
// na x-ovu suradnicu
xCoord = this.getX();
// Ako predosle, ale s y-ovou suradnicou. Kombinujeme vytvorenie
// premennej aj inicializaciu hodnoty do jedneho prikazu
double yCoord = this.getY();
// Dalsie kreslenie
this.step(-legLength);
this.turn(angle);
this.step(legLength);
// Na zaver sa presunieme na ulozenu poziciu bodu A
this.moveTo(xCoord, yCoord);
// Korytnacku presunieme tam, kde bola na zaciatku, a natocime smerom,
// akym bola natocena na zaciatku (pri volani tejto metody)
this.setPosition(startX, startY);
this.setDirection(direction);
}
public void mill(int sailArmCount, double sailArmLength) {
for (int i = 0; i < sailArmCount; i++) {
this.isosceles(sailArmLength, 360.0 / sailArmCount / 2);
this.turn(360.0 / sailArmCount);
}
}
public void rgbChain(int beadCount, double beadRadius) {
for (int i = 0; i < beadCount; i++) {
if (i % 3 == 0) {
this.setFillColor(Color.red);
} else if (i % 3 == 1) {
this.setFillColor(Color.green);
} else {
this.setFillColor(Color.blue);
}
this.dot(beadRadius);
this.penUp();
this.step(2 * beadRadius);
this.penDown();
}
}
public void circleWalk(int stepCount, double radius) {
double x = this.getX();
double y = this.getY();
for (int i = 0; i < stepCount; i++) {
this.turn(Math.random() * 360);
this.step(5);
if (this.distanceTo(x, y) > radius) {
this.step(-5);
}
}
}
public void tripleCircleWalk(int stepCount, double radius) {
double x = this.getX();
double y = this.getY();
for (int i = 0; i < stepCount; i++) {
if (this.distanceTo(x, y) > 2 * radius / 3) {
this.setPenColor(Color.red);
} else {
this.setPenColor(Color.blue);
}
if (this.distanceTo(x, y) < radius / 3) {
this.penUp();
} else {
this.penDown();
}
this.turn(Math.random() * 360);
this.step(5);
if (this.distanceTo(x, y) > radius) {
this.step(-5);
}
}
}
public void squareWalk(int stepCount, double sideLength) {
double x = this.getX();
double y = this.getY();
for (int i = 0; i < stepCount; i++) {
this.turn(Math.random() * 360);
this.step(5);
if (Math.abs(this.getX() - x) > sideLength / 2 ||
Math.abs(this.getY() - y) > sideLength / 2) {
this.step(-5);
}
}
}
public void squareWalkColored(int stepCount, double sideLength) {
double x = this.getX();
double y = this.getY();
for (int i = 0; i < stepCount; i++) {
int reminder = i % 304;
if(reminder < 100) {
this.setPenColor(Color.red);
} else if (reminder < 182) {
this.setPenColor(Color.blue);
} else {
this.setPenColor(Color.black);
}
this.turn(Math.random() * 360);
this.step(5);
if (Math.abs(this.getX() - x) > sideLength / 2 ||
Math.abs(this.getY() - y) > sideLength / 2) {
this.step(-5);
}
}
}
}