import java.awt.Color; import fi.jyu.mit.graphics.*; /** * GuruTask * @author Johannes Neitsch and Kathrin Lembcke * @version 21.09.2008 */ public class Staircase{ /** * * @author vesal * */ public static class Triangle extends DrawableCollection { /** * * @param x * @param y * @param z * @param h */ public Triangle(double x, double y, double z, double h) { move(x, y, z); add(new Line(x,y,z,x+2*h,y,z)); add(new Line(x,y,z,x+h,y+h,z)); add(new Line(x+h,y+h,z,x+2*h,y,z)); } } /** * * @author vesal * */ public static class Stairs extends DrawableCollection { /** * * @param x * @param y * @param z */ public Stairs(double x, double y, double z) { move(x, y, z); add(new Line(x,y,z,x,y+1,z)); add(new Line(x,y+1,z,x+1,y+1,z)); } } /** * * @author vesal * */ public static class StairsDown extends DrawableCollection { /** * * @param x * @param y * @param z */ public StairsDown(double x, double y, double z) { move(x, y, z); add(new Line(x,y,z,x+1,y,z)); add(new Line(x+1,y,z,x+1,y-1,z)); } } /** * * @author vesal * */ public static class RotateTriangle extends DrawableCollection { private Drawable win; /** * * @param dx * @param dy */ public RotateTriangle(double dx,double dy) { move(dx,dy,0.0); add(new Line(-100,-50,100,-50)).move(0,0,0).rotate(0, 0); add(new Line(-100,-50,0,50)).move(0,0,0).rotate(0, 0); add(new Line(0,50,100,-50)).move(0,0,0).rotate(0, 0); } /** * * @param dx * @param dy * @param s * @param deg * @param color */ public RotateTriangle(double dx,double dy, double s, double deg, Color color) { this(dx,dy); if ( s != 1 ) scale(s,s,s); if ( deg != 0 ) rotate(2,deg); if ( color != null ) setColor(color); } /** * * @return win */ public Drawable getWin() { return win; } } /** * * @param args */ public static void main(String[] args) { Window window = new Window(); //create triangle Triangle stairsAndTriangle1 = new Triangle(-2, 0.5, 0, 2); Triangle stairsAndTriangle2 = new Triangle(1, 1, 0, 1); Triangle stairsAndTriangle3 = new Triangle(-1.5, -2, 0, 3); //create and add staircase for(double i= -2;i<0;i=i+0.5){ Stairs stair = new Stairs(i,i,0); window.add(stair); } //create and add downstaircase for(double i= -1;i<1;i=i+0.5){ StairsDown stair = new StairsDown(i+0.5,-i+0.5,0); window.add(stair); } //add triangle window.add(stairsAndTriangle1); window.add(stairsAndTriangle2); window.add(stairsAndTriangle3); window.scale(-4, -4, 4, 4); window.showWindow(); RotateTriangle rotateTriangle = new RotateTriangle(0,0,0.01,180,Color.RED); window.add(rotateTriangle); new ControllerFrame(new TouchPad(rotateTriangle),300,350,150,150); new ControllerFrame(new ControlButtons(rotateTriangle),450,350,150,150); } }