Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F91250299
Cylinder.pde
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Nov 9, 08:54
Size
1 KB
Mime Type
text/x-c++
Expires
Mon, Nov 11, 08:54 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
22229712
Attached To
rBAFOURPROJECT InfoVisuGit
Cylinder.pde
View Options
class Cylinder {
float cylinderBaseSize = 50;
float cylinderHeight = 50;
int cylinderResolution = 40;
PShape openCylinder = new PShape();
PShape closedCylinder = new PShape();
Cylinder() {
float angle;
float[] x = new float[cylinderResolution + 1];
float[] y = new float[cylinderResolution + 1];
//get the x and y position on a circle for all the sides
for (int i = 0; i < x.length; i++) {
angle = (TWO_PI / cylinderResolution) * i;
x[i] = sin(angle) * cylinderBaseSize;
y[i] = cos(angle) * cylinderBaseSize;
}
openCylinder = createShape();
openCylinder.beginShape(QUAD_STRIP);
//draw the border of the cylinder
for (int i = 0; i < x.length; i++) {
openCylinder.vertex(x[i], y[i], 0);
openCylinder.vertex(x[i], y[i], cylinderHeight);
}
openCylinder.endShape();
closedCylinder= createShape();
closedCylinder.beginShape(TRIANGLE_FAN);
closedCylinder.vertex(0, 0, cylinderHeight);
for (int i = 0; i < x.length; i++) {
closedCylinder.vertex(x[i], y[i], cylinderHeight);
}
closedCylinder.endShape();
}
void draw(float x,float y,float z,float r) {
pushMatrix();
translate(x, z, y);
rotateX(r);
shape(openCylinder);
shape(closedCylinder);
popMatrix();
}
}
Event Timeline
Log In to Comment