Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
In this final and longest transformation example, we've put together a series of translate() and rotate() functions to create a linked arm that bends back and forth. Each translate() further moves the position of the lines, and each rotate() adds to the previous rotation to bend more:
floatangle=0.0;floatangleDirection=1;floatspeed=0.005;voidsetup(){size(120,120);smooth();}voiddraw(){background(204);translate(20,25);// Move to start positionrotate(angle);strokeWeight(12);line(0,0,40,0);translate(40,0);// Move to next jointrotate(angle*2.0);strokeWeight(6);line(0,0,30,0);translate