A2

Utorok 1

import java.awt.Color;

import sk.upjs.jpaz2.Turtle;

public class ChytraTurtle extends Turtle {

        public void retiazka(int pocetKoralov, double polomerKoralu) {
                this.setFillColor(Color.blue);
                this.penUp();

                for (int i = 0; i < pocetKoralov; i++) {
                        this.dot(polomerKoralu);
                        this.step(2 * polomerKoralu);
                }

                this.penDown();
        }

        public void nUholnik(int n, double dlzkaStrany) {
                for (int i = 0; i < n; i++) {
                        this.step(dlzkaStrany);
                        this.turn(360.0 / n);
                }
        }

        public void rovnoramenny(double uhol, double rameno) {
                double startX = this.getX();
                double startY = this.getY();
                double natocenie = this.getDirection();

                this.turn(-uhol / 2);
                this.step(rameno);
                double xA = this.getX();
                double yA = this.getY();
                this.step(-rameno);
                this.turn(uhol);
                this.step(rameno);
                this.moveTo(xA, yA);

                this.setPosition(startX, startY);
                this.setDirection(natocenie);
        }

        public void mlyn(int pocetRamien, double dlzkaRamena) {
                double uholLopatky = 360.0 / (2 * pocetRamien);
                for (int i = 0; i < pocetRamien; i++) {
                        this.rovnoramenny(uholLopatky, dlzkaRamena);
                        this.turn(2 * uholLopatky);
                }
        }

        public void retiazkaRGB(int pocetKoralov, double polomerKoralu) {
                this.penUp();

                int poradie = 1;
                for (int i = 0; i < pocetKoralov; i++) {
                        if (poradie % 3 == 1) {
                                this.setFillColor(Color.red);
                        }

                        if (poradie % 3 == 2) {
                                this.setFillColor(Color.green);
                        }

                        if (poradie % 3 == 0) {
                                this.setFillColor(Color.blue);
                        }

                        this.dot(polomerKoralu);
                        poradie++; // poradie = poradie + 1;
                        this.step(2 * polomerKoralu);
                }

                this.penDown();
        }
}

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);
        }

}