CIS 3.5 - Spring 2010 Classes & 3D M. Meyer */ /** ******************** Variables: Variables provide a way to save information within your sketch and use it to control the size, position, shape, etc. of what you are drawing. */ float offsetX = 300; float offsetY = 150; float focalLength = 400; // Front Square Point_3D p1 = new Point_3D(-50,-50,0); Point_3D p2 = new Point_3D(50,-50,0); Point_3D p3 = new Point_3D(50,50,0); Point_3D p4 = new Point_3D(-50,50,0); // Back Square Point_3D p5 = new Point_3D(-50,-50,50); Point_3D p6 = new Point_3D(50,-50,50); Point_3D p7 = new Point_3D(50,50,50); Point_3D p8 = new Point_3D(-50,50,50); /** ******************** setup(): Use setup() to specify things that need to be done once, when the sketch first opens. */ void setup() { background(#ffffff); size(600, 300); } /** ******************** Use draw() to specify things that you want to have done repeatedly. NOTE: draw() must be present in your program, even if it is left empty. */ void draw() { //Clear any previous images background(#ffffff); //Update all points p1.update(); p2.update(); p3.update(); p4.update(); p5.update(); p6.update(); p7.update(); p8.update(); //Draw all front lines stroke(#ff0000); line(p1.Px, p1.Py, p2.Px, p2.Py); line(p2.Px, p2.Py, p3.Px, p3.Py); line(p3.Px, p3.Py, p4.Px, p4.Py); line(p4.Px, p4.Py, p1.Px, p1.Py); // Draw all back lines stroke(#00ff00); line(p5.Px, p5.Py, p6.Px, p6.Py); line(p6.Px, p6.Py, p7.Px, p7.Py); line(p7.Px, p7.Py, p8.Px, p8.Py); line(p8.Px, p8.Py, p5.Px, p5.Py); // Draw all connecting lines stroke(#0000ff); line(p5.Px, p5.Py, p1.Px, p1.Py); line(p6.Px, p6.Py, p2.Px, p2.Py); line(p7.Px, p7.Py, p3.Px, p3.Py); line(p8.Px, p8.Py, p4.Px, p4.Py); } /** ******************** Event Listners: Use event-listners like keyPressed() to allow users of your program to cause things to happen. */ void keyPressed() { if (key == CODED) { if (keyCode == UP) { p1.z += 10; p2.z += 10; p3.z += 10; p4.z += 10; p5.z += 10; p6.z += 10; p7.z += 10; p8.z += 10; } else if (keyCode == DOWN) { p1.z -= 10; p2.z -= 10; p3.z -= 10; p4.z -= 10; p5.z -= 10; p6.z -= 10; p7.z -= 10; p8.z -= 10; } else if (keyCode == RIGHT) { p1.x += 10; p2.x += 10; p3.x += 10; p4.x += 10; p5.x += 10; p6.x += 10; p7.x += 10; p8.x += 10; } else if (keyCode == LEFT) { p1.x -= 10; p2.x -= 10; p3.x -= 10; p4.x -= 10; p5.x -= 10; p6.x -= 10; p7.x -= 10; p8.x -= 10; } } } /** ******************** Functions: Functions are sections of code that you create and name. */ /** ******************** Classes: Used to create objects.

Source code: Simple3D_Using_Classes

Built with Processing