Code
This page will always be updated with the latest code and descriptions.
So I decided to use processing for the code, which is an offshoot of Java, this decision was mainly because Processing’s ease of readability made it ideal for working with structurally as well as allowing people not extremely proficient in programming to be able to read the code. When I pasted the code into this screen it took away my indentation, which is sort of ironic as this project is about the beauty of well structured code, this is a HTML issue that I will figure out how to get around in the future. Either way, here is the processing code that I have been working on thus far. It produces a cylinder to the screen and that cylinder is alterable in rotation and color. This isn’t going to be a part of the final application, but it is ideal for testing. The applet can be downloaded here (Right click -> Save As). Rename the file extension from .jpg to .zip, unzip it and open index.html. The file extension renaming thing is because WordPress won’t allow me to upload a .zip file.
import processing.core.*;
public class BasicCylinder extends PApplet{
//color and opacity values for drawing
private float red = 150, green = 150, blue = 150;
private float opacity = 255;
//shape rotation values
private float zRotation = (float) 0;
private float xRotation = (float) -(0.5);
private float yRotation = (float) 0;
/**
* setup
* do all of the things that should be done before objects are
* drawn to the stage.
*/
public void setup(){
size(800, 600, P3D); //the size of the stage
}
/**
* draw
* repeatedly called to keep drawing to the screen.
*/
public void draw(){
lights(); //give the stage some ambient light
background(0, 0, 0); //the background color in RGB
fill(red, green, blue, opacity);//the color of the next drawn object in RGB
// stroke(255); //wire set wire frame to white
noStroke(); //hide the wire frame
// noFill(); //hide the object’s solidity
/* pushMatrix starts developing shape */
pushMatrix();
translate(width/2, height/2-100, 0); //moves the shape to this location
rotateX((float) xRotation); //rotates the shape around the x axis
rotateY((float) yRotation); //rotates the shape around the y axis
rotateZ((float) zRotation); //rotates the shape around the z axis
//draw a cylinder object to the screen at the location specified above
drawCylinder((float)100, (float)100, (float)350, 120);
popMatrix();
/* popMatrix draws the shape to the screen */
}
/**
* drawCylinder
* draws a cylinder of the specified dimensions to the screen.
* @param topRadius
* @param bottomRadius
* @param tall
* @param sides
*/
public void drawCylinder(float topRadius, float bottomRadius, float tall, int sides) {
float angle = 0;
float angleIncrement = TWO_PI / sides;
/* define the shape of a side of the cylinder. */
beginShape(QUAD_STRIP);
//for each side draw a plane and increase the angle around the cylinder
for (int i = 0; i < sides + 1; ++i) {
vertex(topRadius*cos(angle), 0, topRadius*sin(angle));
vertex(bottomRadius*cos(angle), tall, bottomRadius*sin(angle));
angle += angleIncrement;
}
endShape();
/* If it is not a cone, draw the circular top cap */
if (topRadius != 0) {
angle = 0;
beginShape(TRIANGLE_FAN);
// Center point
vertex(0, 0, 0);
//for each side draw a triangle from the top of the plane to the center of the top cap
for (int i = 0; i < sides + 1; i++) {
vertex(topRadius * cos(angle), 0, topRadius * sin(angle));
angle += angleIncrement;
}
endShape();
}
/* If it is not a cone, draw the circular bottom cap */
if (bottomRadius != 0) {
angle = 0;
beginShape(TRIANGLE_FAN);
// Center point
vertex(0, tall, 0);
//for each side draw a triangle from the bottom of the plane to the center of the bottom cap
for (int i = 0; i = 5){ red -= 5; }
}
else if(key == ’2′){
if(red = 5){ green -= 5; }
}
else if(key == ’4′){
if(green = 5){ blue -= 5; }
}
else if(key == ’6′){
if(blue = 5){ opacity -= 5; }
}
else if(key == ’8′){
if(opacity <= 250){ opacity += 5; }
}
}
}