Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F91647895
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
Wed, Nov 13, 01:48
Size
1 KB
Mime Type
text/x-c
Expires
Fri, Nov 15, 01:48 (2 d)
Engine
blob
Format
Raw Data
Handle
22295779
Attached To
rBAFOURPROJECT InfoVisuGit
cylinder.pde
View Options
float cylinderBaseSize = 50;
float cylinderHeight = 50;
int cylinderResolution = 40;
PShape openCylinder = new PShape();
PShape closedCylinder = new PShape();
void settings() {
size(400, 400, P3D);
}
void setup() {
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() {
background(255);
translate(mouseX, mouseY, 0);
shape(openCylinder);
shape(closedCylinder);
}
Event Timeline
Log In to Comment