mu chance or much chance ?

日々の戯れ言

ProcessingのPythonモード 勉強3

以下の本を読みながら,
ProcessingのPythonモードを勉強しています.
第3章前半です.

  • list3_1.pyde
# i = 0

def setup():
    size(800, 600)
    frameRate(60)
    background(0)
    noStroke()
        
def draw():
#    global i
    x = random(0, width)
    y = random(0, height)
    d = dist(x, y, width / 2, height / 2)
    if d < height / 2:
        noStroke()
        fill(63, 127, 255)
    else:
        noFill()
        stroke(31, 127, 255)
    ellipse(x, y, 10, 10)
#    saveFrame("frames/####.png")
#    i += 1
#    if i >= 1000:
#        noLoop()
  • 出力結果

  • list3_2.pyde
# i = 0

def setup():
    size(800, 600)
    frameRate(60)
    background(0)
    noStroke()

def draw():
#    global i
    x = random(0, width)
    y = random(0, height)
    d = dist(x, y, width / 2, height / 2)
    diameter = 30 - d / 10.0
        
    if diameter > 0:
        fill(63, 127, 255)
        ellipse(x, y, diameter, diameter)

#    saveFrame("frames/####.png")
#    i += 1    
#    if i >= 1000:
#        noLoop()
  • 出力結果

  • list3_3.pyde
# i = 0

locationX = 0
direction = -1

def setup():
    size(800, 600)
    frameRate(60)
    fill(0, 127, 255)
    noStroke()

def draw():
#    global i
    global locationX, direction
    background(0)
    ellipse(locationX, height / 2, 20, 20)
    locationX +=  10 * direction
    if locationX < 0 or locationX > width:
        direction *= -1

#    saveFrame("frames/####.png")
#    i += 1    
#    if i >= 1000:
#        noLoop()
  • 出力結果

  • list3_4.pyde
# i = 0

def setup():
    size(800, 600)
    frameRate(60)
    colorMode(HSB, 360, 100, 100, 100)
    noStroke()
        
def draw():
#    global i
    background(0);
    diameter = 400 + sin(frameCount * 0.1) * 200
    hue = sin(frameCount * 0.1) * 120
    fill(hue, 100, 100)
    ellipse(width / 2, height / 2, diameter, diameter)
    
#    saveFrame("frames/####.png")
#    i += 1
#    if i >= 1000:
#        noLoop()
  • 出力結果