RotateΒΆ
Rotating a square around the Z axis. To get the results you expect, send the rotate function angle parameters that are values between 0 and PI*2 (TWO_PI which is roughly 6.28). If you prefer to think about angles as degrees (0-360), you can use the radians() method to convert your values. For example: scale(radians(90)) is identical to the statement scale(PI/2).
from p5 import *
angle = 0.0
jitter = 0.0
def setup():
size(640, 360)
fill(255)
no_stroke()
def draw():
background(102)
global angle
global jitter
if second()%2 == 0:
jitter = random_uniform(-0.1, 0.1)
angle = angle + jitter
c = cos(angle)
translate(width/2, height/2)
rotate(c)
rect((-90, -90), 180, 180)
if __name__ == '__main__':
run()