B2

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.penUp();
                this.setFillColor(Color.BLUE);

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

        public void isosceles(double legLength, double angle) {
                double startX = this.getX();
                double startY = this.getY();
                double direction = this.getDirection();
                this.turn(-angle / 2);
                this.step(legLength);
                double xCoord;
                xCoord = this.getX();
                double yCoord = this.getY();
                this.step(-legLength);
                this.turn(angle);
                this.step(legLength);
                this.moveTo(xCoord, yCoord);
                this.setPosition(startX, startY);
                this.setDirection(direction);
        }

        public void mill(int count, double length) {
                double angle = 360.0 / (2 * count);
                for (int i = 0; i < count; i++) {
                        this.isosceles(length, angle);
                        this.turn(2 * angle);
                }
        }

        public void rgbChain(int beadCount, double beadRadius) {
                this.penUp();

                for (int i = 0; i < beadCount; i++) {


                        this.dot(beadRadius);
                        this.step(2 * beadRadius);
                }
        }

}
package sk.paz1a.practicals.task2;

import java.util.Iterator;

import sk.upjs.jpaz2.*;

public class Launcher {

        public static void main(String[] args) {
                // create new "sandbox" - a place where turtles can live
                AnimatedWinPane sandbox = new AnimatedWinPane();

                // create new turtle and add it to the "sandbox"
                SmartTurtle franklin = new SmartTurtle();
                sandbox.add(franklin);

                // create new object inspector
                ObjectInspector oi = new ObjectInspector();
                // ask the inspector to inspect "franklin" and "sandbox"
                oi.inspect(franklin);
                oi.inspect(sandbox);

                // you can put other initialization commands here
                //franklin.turn(134);
                //franklin.chain(8, 6.4568);
                //franklin.ngon(7846, 1);
                //franklin.mill(3, 30);

                for (int i = 3; i < 20; i++) {
                        franklin.ngon(i, 20);
                }

        }
}
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.penUp();
                this.setFillColor(Color.BLUE);

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

        public void isosceles(double legLength, double angle) {
                double startX = this.getX();
                double startY = this.getY();
                double direction = this.getDirection();
                this.turn(-angle / 2);
                this.step(legLength);
                double xCoord;
                xCoord = this.getX();
                double yCoord = this.getY();
                this.step(-legLength);
                this.turn(angle);
                this.step(legLength);
                this.moveTo(xCoord, yCoord);
                this.setPosition(startX, startY);
                this.setDirection(direction);
        }

        public void mill(int count, double length) {
                double angle = 360.0 / (2 * count);
                for (int i = 0; i < count; i++) {
                        this.isosceles(length, angle);
                        this.turn(2 * angle);
                }
        }

        // nedokoncena uloha
        public void rgbChain(int beadCount, double beadRadius) {
                this.penUp();

                for (int i = 0; i < beadCount; i++) {

                        this.dot(beadRadius);
                        this.step(2 * beadRadius);
                }
        }

        public void circleWalk(int stepCount, double radius) {
                double startX = this.getX();
                double startY = this.getY();
                double startDirection = this.getDirection();

                for (int i = 0; i < stepCount; i++) {
                        this.turn(Math.random() * 360);
                        this.step(5);

                        // je mimo ak je vzdialenost aktualnej pozicie
                        // od zaciatku vacsia ako radius

                        if (this.distanceTo(startX, startY) > radius) {
                                this.step(-5);
                        }
                }

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

        public void tripleCircleWalk(int stepCount, double radius) {
                double startX = this.getX();
                double startY = this.getY();
                double startDirection = this.getDirection();

                for (int i = 0; i < stepCount; i++) {
                        double distance = this.distanceTo(startX, startY);

                        // penUp/down
                        if (distance < radius / 3) {
                                this.penUp();
                        } else {
                                this.penDown();
                        }

                        // farba
                        if (distance > (radius * 2 / 3)) {
                                this.setPenColor(Color.RED);
                        } else {
                                this.setPenColor(Color.BLUE);
                        }

                        this.turn(Math.random() * 360);
                        this.step(5);

                        // ci je mimo
                        if (distance > radius) {
                                this.step(-5);
                        }
                }

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

        public void squareWalk(int stepCount, double sideLength) {
                double startX = this.getX();
                double startY = this.getY();
                double startDirection = this.getDirection();

                for (int i = 0; i < stepCount; i++) {
                        this.turn(Math.random() * 360);
                        this.step(5);

                        double lavyOkraj = startX - sideLength / 2;
                        boolean vlavo = this.getX() < lavyOkraj;

                        boolean vpravo = this.getX() > startX + sideLength / 2;
                        boolean hore = this.getY() < startY - sideLength / 2;
                        boolean dole = this.getY() > startY + sideLength / 2;

                        boolean podlaXjeMimo = vlavo || vpravo;
                        boolean podlaYjeMimo = hore || dole;

                        if (podlaYjeMimo || podlaXjeMimo) {
                                this.step(-5);
                        }
                }

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

        public void circleWalkLimitedEdition(int stepCount, double radius) {
                double startX = this.getX();
                double startY = this.getY();
                double startDirection = this.getDirection();

                for (int i = 0; i < stepCount; i++) {




                        int direction = 90 * (int)(Math.random() * 4);
                        this.setDirection(direction);






                        this.step(5);

                        // je mimo ak je vzdialenost aktualnej pozicie
                        // od zaciatku vacsia ako radius

                        if (this.distanceTo(startX, startY) > radius) {
                                this.step(-5);
                        }
                }

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

}