コード例 #1
0
            erad = 5.0 * (1.0 - float(i) / len(sines)
                          )  # pen width will be related to which sine

        radius = rad / (i + 1)  # radius for circle itself
        rotate(sines[i])  # rotate circle
        if not trace:
            ellipse(0, 0, radius * 2,
                    radius * 2)  # if we're simulating, draw the sine
        push()  # go up one level
        translate(0, radius)  # move to sine edge
        if not trace: ellipse(0, 0, 5, 5)  # draw a little circle
        if trace: ellipse(0, 0, erad, erad)  # draw with erad if tracing
        pop()  # go down one level
        translate(0, radius)  # move into position for next sine
        sines[i] = (
            sines[i] +
            (fund +
             (fund * i * ratio))) % TWO_PI  # update angle based on fundamental

    pop()  # pop down final transformation


def keyReleased():
    global trace
    if key == ' ':
        trace = not trace
        background(255)


run()
コード例 #2
0
import p5py


def setup():
    createCanvas(700, 410)
    background(200)


def draw():
    if mouseIsPressed: ellipse(mouseX, mouseY, 50, 50)


def keyPressed():
    background(200)


p5py.run()