E1

21.09.2012

import java.awt.Color;
import sk.upjs.jpaz2.*;

public class Spustac {

        /**
         * @param args
         */

        public static void main(String[] args) {
                WinPane plocha = new WinPane();
                ObjectInspector oi = new ObjectInspector();
                oi.inspect(plocha);

                Turtle zofka = new Turtle();
                plocha.add(zofka);
                zofka.setPosition(100, 150);
                zofka.setPenColor(Color.RED);
                oi.inspect(zofka);

                Turtle jozko = new Turtle();
                plocha.add(jozko);
                jozko.setPosition(200, 150);
                jozko.setPenColor(Color.BLUE);
                oi.inspect(jozko);

                for (int i = 0; i < 4; i++) {
                        jozko.step(50);
                        jozko.turn(90);
                        JPAZUtilities.delay(1000);
                }

                ChytraTurtle albert = new ChytraTurtle();
                plocha.add(albert);
                oi.inspect(albert);
                albert.setPosition(plocha.getWidth()/2, plocha.getHeight()/2);

        }

}
import java.awt.Color;

import sk.upjs.jpaz2.*;

/**
 *
 */


/**
 * @author student
 *
 */

public class ChytraTurtle extends Turtle {

        public void spomalenyStvorec() {
                for (int i = 0; i < 4; i++) {
                        this.step(70);
                        this.turn(90);
                        JPAZUtilities.delay(500);
                }
        }

        public void trojuholnik(double dlzkaStrany) {
                for (int i = 0; i < 3; i++) {
                        this.step(dlzkaStrany);
                        this.turn(120);
                }
        }

        public void rgbTrojuholnik(double dlzkaStrany) {
                // odlozenie povodnych hodnot
                Color povodnaFarba = this.getPenColor();
                double povodnaHrubkaPera = this.getPenWidth();

                this.setPenWidth(2);
                // cervena strana
                this.setPenColor(Color.RED);
                this.step(dlzkaStrany);
                this.turn(120);
                // zelena strana
                this.setPenColor(Color.GREEN);
                this.step(dlzkaStrany);
                this.turn(120);
                // modra strana
                this.setPenColor(Color.BLUE);
                this.step(dlzkaStrany);
                this.turn(120);
                // vratenie povodnych hodnot
                this.setPenColor(povodnaFarba);
                this.setPenWidth(povodnaHrubkaPera);
        }

        public void stvorec(double dlzkaStrany) {
                for (int i = 0; i < 4; i++) {
                        this.step(dlzkaStrany);
                        this.turn(90);
                }
        }

        public void domcek(double dlzkaStrany) {
                this.stvorec(dlzkaStrany);
                this.step(dlzkaStrany);
                this.turn(30);
                this.trojuholnik(dlzkaStrany);

        }

        public void ciarkaBodkaCiarka(double dlzka) {
                Color farba = this.getFillColor();

                this.setFillColor(Color.yellow);

                this.step(dlzka/3);
                this.penUp();
                this.step(dlzka/6);
                this.dot(dlzka/10);
                this.step(dlzka/6);
                this.penDown();
                this.step(dlzka/3);

                this.setFillColor(farba);
        }

        public void slniecko(double polomer) {
                this.setPenColor(Color.ORANGE);
                for (int i = 0; i < 36; i++) {
                        this.step(polomer*2);
                        this.step(-polomer*2);
                        this.turn(10);
                }
                this.setFillColor(Color.yellow);
                this.dot(polomer);
        }

        public void vrtulka(double dlzka) {
                for (int i = 0; i < 8; i++) {
                        this.step(dlzka);
                        this.turn(45);
                        this.step(10);
                        this.step(-10);
                        this.turn(-45);
                        this.step(-dlzka);
                        this.turn(360/8);
                }
        }

        public void kriz(double strana) {
                //nastavenie pera
                this.setPenColor(Color.red);
                this.setPenWidth(2);

                for (int i = 0; i < 4; i++) {
                        this.step(strana);
                        this.turn(90);
                        this.step(strana);
                        this.turn(90);
                        this.step(strana);
                        this.turn(-90);
                }
        }

        public void obrazec (double strana) {
                this.setPenColor(Color.blue);
                this.setPenWidth(2);

                for (int i = 0; i < 10; i++) {
                        this.stvorec(strana);
                        this.turn(90);
                        this.step(strana/2);
                        this.turn(-54);
                }
        }

        public void vyplneny6uholnik(double strana) {
                this.openPolygon();
                this.penUp();
                for (int i = 0; i < 6; i++) {
                        this.step(strana);
                        this.turn(60);
                }
                this.penDown();
                this.closePolygon();
        }
}