How to rotate the cylinder in Processing?

edited February 2016 in How To...

I have drawn the 3D cylinder in Processing based on http://vormplus.be/blog/article/drawing-a-cylinder-with-processing. i have to move/rotate the cylinder but only one face should rotate just like pendulum (top is always fixed and bottom is moving).. similarly my bottom face of the 3D cylinder should move and top face should be fixed. How to do that?

Answers

  • you need to place the point that needs to be fixed (top face) on the origin (0,0)

    then use rotateZ(angleZ); and translate(width/2,height/2);

    before setup():

    float angleZ; 
    float addAngleZ = .01; 
    

    and then at the end of draw()

    angleZ+=addAngleZ; 
    
    if (angleZ>1.2)
        addAngleZ*=-1; 
    
Sign In or Register to comment.