Thanks! I adapted the code and this seems to work just fine:
Code: /*
*
*/
color colorA;
color colorB;
void setup() {
size(600,400,P3D);
// smooth();
noStroke();
colorMode(HSB,100);
}
void draw()
{
background(1,0,20);
lights();
colorA = color(frameCount%100,90,100);
colorB = color(100-frameCount%100,90,100);
translate(200,200);
rotateX(frameCount*0.01);
rotateY(frameCount*0.02);
rotateZ(frameCount*0.03);
cylinder(10,200,20,colorA,colorB);
translate(30,0);
cylinder(10,200,20,colorA,colorB);
translate(30,0);
cylinder(10,200,20,colorA,colorB);
translate(30,0);
cylinder(10,200,20,colorA,colorB);
translate(-90,0);
}
void cylinder(float w, float h, int sides, color colorTop, color colorBottom)
{
float angle;
float[] x = new float[sides+1];
float[] z = new float[sides+1];
//get the x and z position on a circle for all the sides
for(int i=0; i < x.length; i++){
angle = TWO_PI / (sides) * i;
x[i] = sin(angle) * w;
z[i] = cos(angle) * w;
}
//draw the top of the cylinder
beginShape(TRIANGLE_FAN);
fill(colorTop);
vertex(0, -h/2, 0);
for(int i=0; i < x.length; i++){
vertex(x[i], -h/2, z[i]);
}
endShape();
//draw the center of the cylinder
beginShape(QUAD_STRIP);
for(int i=0; i < x.length; i++){
fill(colorTop);
vertex(x[i], -h/2, z[i]);
fill(colorBottom);
vertex(x[i], h/2, z[i]);
}
endShape();
//draw the bottom of the cylinder
beginShape(TRIANGLE_FAN);
fill(colorBottom);
vertex(0, h/2, 0);
for(int i=0; i < x.length; i++){
vertex(x[i], h/2, z[i]);
}
endShape();
}