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()
  • 出力結果

ProcessingのPythonモード 勉強2

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

  • list2_1.pyde
size(800, 600)
colorMode(HSB, 360, 100, 100, 100)

background(0)
noStroke()

hue = 200
saturation = 100
brightness = 20
alpha = 90
diameter = width / 2
col = color(hue, saturation, brightness, alpha)
fill(col)
ellipse(width / 8, height / 2, diameter, diameter)

brightness += 20
col = color(hue, saturation, brightness, alpha)
fill(col)
ellipse(width / 8 * 3, height / 2, diameter, diameter)

brightness += 20
col = color(hue, saturation, brightness, alpha)
fill(col)
ellipse(width / 8 * 5, height / 2, diameter, diameter)

brightness += 20
col = color(hue, saturation, brightness, alpha)
fill(col)
ellipse(width / 8 * 7, height / 2, diameter, diameter)
  • 出力結果

f:id:muchance:20180630221139p:plain

  • list2_2.pyde
size(800, 600)
colorMode(HSB, 360, 100, 100, 100)
background(0)
noStroke()

num = 12
hue = 200
saturation = 100
brightness = 20
alpha = 90
diameter = width / num * 2

for i in range(num):
    col = color(hue, saturation, brightness, alpha);
    fill(col)
    x = width / num * i + diameter / 4
    ellipse(x, height / 2, diameter, diameter)
    brightness += 100 / num;
  • 出力結果

f:id:muchance:20180630221241p:plain

  • list2_3.pyde
size(800, 600)
background(0)
noStroke()

num = 10000

for i in range(num):
    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)
  • 出力結果

f:id:muchance:20180630221902p:plain

ProcessingのPythonモード 勉強1

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

  • list1_1.pyde
size(800, 600)[f:id:muchance:20180630212208p:plain]
point(100, 200)
line(80, 40, 700, 500)
rect(200, 300, 400, 200)
ellipse(500, 300, 300, 200)
  • 出力結果

f:id:muchance:20180630211344p:plain

  • list1_2.pyde
size(640, 480)
background(0)
stroke(255, 255, 31)
fill(31, 127, 255)
point(200, 200)
line(80, 40, 600, 400)
rect(300, 200, 200, 180)
ellipse(450, 200, 200, 100)
  • 出力結果

f:id:muchance:20180630212208p:plain

  • list1_3.pyde
size(640, 480)
background(0)
stroke(255, 255, 31)
fill(31, 127, 255, 127)
point(200, 200)
line(80, 40, 600, 400)
rect(300, 200, 200, 180)
ellipse(450, 200, 200, 100)
  • 出力結果

f:id:muchance:20180630212517p:plain

  • list1_4.pyde
size(640, 480)
background(0)
stroke(255, 255, 31)
point(200, 200)
line(80, 40, 600, 400)

fill(31, 127, 255, 127)
rect(300, 200, 200, 180)

fill(255, 127, 31, 127)
ellipse(450, 200, 200, 100)
  • 出力結果

f:id:muchance:20180630212728p:plain

  • list1_5.pyde
size(640, 480)
colorMode(HSB, 360, 100, 100, 100)
background(0)
stroke(60, 30, 80)
point(200, 200)
line(80, 40, 600, 400)

fill(30, 80, 80, 50)
rect(300, 200, 200, 180)

fill(200, 80, 80, 50)
ellipse(450, 200, 200, 100)
  • 出力結果

f:id:muchance:20180630213047p:plain