# example1.py
# Rotating ellipse and words

from Processing import *
window(500, 500)

# Draw a grid
def grid():
    x1, x2, dx = -100.0, 100.0, 10.0
    y1, y2, dy = -100.0, 100.0, 10.0

    # Draw grid
    stroke(225,225,255)

    x = x1
    while x <= x2:
        line(x,y1,x,y2)
        x+=dx
    y = y1
    while y <= y2:
        line(x1,y,x2,y)
        y+=dy

    # Draw axes
    inc = 0.005*width()
    inc2 = 2.0*inc
    stroke(0)
    fill(0)
    line(x1,0,x2,0)
    triangle(x2+inc2,0,x2,inc,x2,-inc)
    text("x",x2+2*inc2,inc2)
    line(0,y1,0,y2)
    triangle(0,y2+inc2,inc,y2,-inc,y2)
    text("y",inc2,y2+2*inc2)

# ----------
angle = 0.0

def draw(o, e):
    background(255)

    # Translate to the center of the sketch,
    # scale by 2, and rotate
    translate(250.0,250.0)
    scale(2.0)
    rotate(angle)
    drawTest()

    # Increment global angle
    global angle
    angle = angle - (PI/180.0)

def drawTest():
    # Draw a rotated ellipse
    stroke(0)
    fill(255,200,200)
    ellipse(0,0,100,50)

    # Draw several words around a circle
    textAngle = TWO_PI/6.0

    noStroke()
    fill(0)
    text("Hey!", 60, 0)
    rotate(textAngle)
    text("How", 60, 0)
    rotate(textAngle)
    text("did", 60, 0)
    rotate(textAngle)
    text("he", 60, 0)
    rotate(textAngle)
    text("do", 60, 0)
    rotate(textAngle)
    text("that?", 60, 0)
    rotate(textAngle)

frameRate(20)
onLoop += draw
loop()
