import java.awt.Color;
import sk.upjs.jpaz2.Turtle;
public class ChytraTurtle extends Turtle {
public void zabradlie(double vyska, double rozostup) {
for (int i = 0; i < 5; i++) {
this.step(vyska);
this.turn(90);
this.step(rozostup);
this.turn(90);
this.step(vyska);
this.turn(180);
}
}
public void trojuholnik(double strana) {
for (int i = 0; i < 3; i++) {
this.step(strana);
this.turn(120);
}
}
public void stvorec(double strana) {
for (int i = 0; i < 4; i++) {
this.step(strana);
this.turn(90);
}
}
public void domcek(double dlzkaStrany) {
this.stvorec(dlzkaStrany);
this.step(dlzkaStrany);
this.turn(30);
this.trojuholnik(dlzkaStrany);
this.turn(-30);
this.step(-dlzkaStrany);
}
public void slniecko(double polomer) {
this.setPenColor(Color.orange);
for (int i = 0; i < 36; i++) {
this.step(2 * polomer);
this.step(-2 * polomer);
this.turn(360 / 36);
}
this.setFillColor(Color.yellow);
this.dot(polomer);
}
public void vyplnenyStvorec(double strana) {
this.setFillColor(Color.blue);
this.openPolygon();
this.penUp();
for (int i = 0; i < 4; i++) {
this.step(strana);
this.turn(90);
}
this.penDown();
this.closePolygon();
}
public void vystredenyStvorec(double dlzkaStrany) {
this.penUp();
this.step(dlzkaStrany / 2);
this.turn(90);
this.penDown();
this.step(dlzkaStrany / 2);
for (int i = 0; i < 3; i++) {
this.turn(90);
this.step(dlzkaStrany);
}
this.turn(90);
this.step(dlzkaStrany / 2);
this.turn(90);
this.penUp();
this.step(dlzkaStrany / 2);
this.turn(180);
this.penDown();
}
public void pochodzkaKruh(int pocetKrokov, double polomer) {
double startX = this.getX();
double startY = this.getY();
double smer = this.getDirection();
for (int i = 0; i < pocetKrokov; i++) {
this.turn(Math.random() * 360);
int r = (int)(Math.random()*256);
int g = (int)(Math.random()*256);
int b = (int)(Math.random()*256);
this.setPenColor(new Color(r, g, b));
this.step(5);
if (this.distanceTo(startX, startY) > polomer) {
this.step(-5);
}
}
this.setPosition(startX, startY);
this.setDirection(smer);
}
public void pochodzkaTrojkruh(int pocetKrokov, double polomer) {
double startX = this.getX();
double startY = this.getY();
double smer = this.getDirection();
for (int i = 0; i < pocetKrokov; i++) {
this.turn(Math.random() * 360);
double vzdialenost = this.distanceTo(startX, startY);
if (vzdialenost > (2 / 3.0) * polomer) {
this.setPenColor(Color.red);
} else {
this.setPenColor(Color.blue);
}
if (vzdialenost > polomer / 3.0) {
this.penDown();
} else {
this.penUp();
}
this.step(5);
if (this.distanceTo(startX, startY) > polomer) {
this.step(-5);
}
}
this.setPosition(startX, startY);
this.setDirection(smer);
}
public void pochodzkaStvorec(int pocetKrokov, double strana) {
double startX = this.getX();
double startY = this.getY();
double smer = this.getDirection();
for (int i = 0; i < pocetKrokov; i++) {
this.turn(Math.random() * 360);
this.step(5);
// boolean vXPase = (startX - strana / 2 <= this.getX())
// && (this.getX() <= startX + strana / 2);
boolean vXPase = Math.abs(startX - this.getX()) <= strana / 2;
boolean vYPase = (startY - strana / 2 <= this.getY())
&& (this.getY() <= startY + strana / 2);
boolean somVStvorci = vXPase && vYPase;
if (!somVStvorci) {
this.step(-5);
}
}
this.setPosition(startX, startY);
this.setDirection(smer);
}
}