10. NodeBox
• Experimental Media Research Group, Sint Lucas School of arts(ベルギー)で開発
• 複数バージョンが存在
• NodeBox 3
• 最新版
• マルチプラットフォーム
• Node型のプログラミング環境(拡張はPythonで記述)で開発・実行環境を提供
• NodeBox 1
• Mac OS X のみ開発・実行環境を提供
• インターフェースはPython
• NodeBox OpenGL
• マルチプラットフォーム
• Pythonのライブラリとして提供
13年9月15日日曜日
26. Noise 処理(Perlin Noise)
noise = ximport("noise")
size(500, 100)
stroke(0,0,0)
strokewidth(5)
step = 10
borderx = 20
lastx = -999
lasty = -999
ynoise = random()
for x in range(borderx, (WIDTH - borderx), step):
y = 10 + noise.generate(ynoise) * 80
if (lastx > -999):
line(x, y, lastx, lasty)
lastx = x
lasty = y
ynoise += 0.1
ステップ毎にYをランダム(パーリンノイズ)な値に
13年9月15日日曜日
27. Noise 処理(ランダムな円の描画)
from math import sin, cos, radians
size(500, 300)
fill(0,0,0)
radius = 100
centx = WIDTH/2
centy = HEIGHT/2
for ang in range(0, 360, 5):
rad = radians(ang)
x = centx + (radius * cos(rad))
y = centy + (radius * sin(rad))
oval(x, y, 5, 5)
θ
(sin θ, cos θ)
点線の円を描画
13年9月15日日曜日
28. Noise 処理(ランダムな円の描画)
from math import sin, cos, radians
size(500, 300)
stroke(0,0,0)
strokewidth(1)
radius = 10
centx = WIDTH/2
centy = HEIGHT/2
lastx = -999
lasty = -999
for ang in range(0, 1440, 5):
radius += 0.5
rad = radians(ang)
x = centx + (radius * cos(rad))
y = centy + (radius * sin(rad))
if (lastx > -999):
line(x, y, lastx, lasty)
lastx = x
lasty = y
円を螺旋に変更
13年9月15日日曜日
29. Noise 処理(ランダムな円の描画)
from math import sin, cos, radians
noise = ximport("noise")
size(500, 300)
stroke(0,0,0)
strokewidth(5)
radiusnoise = random()
radius = 10
centx = WIDTH/2
centy = HEIGHT/2
lastx = -999
lasty = -999
for ang in range(0, 1440, 5):
radiusnoise += 0.05
radius += 0.5
n_radius = radius + (noise.generate(radiusnoise)
* 200) - 100
rad = radians(ang)
x = centx + (n_radius * cos(rad))
y = centy + (n_radius * sin(rad))
if (lastx > -999):
line(x, y, lastx, lasty)
lastx = x
lasty = y
螺旋にNoiseを追加
13年9月15日日曜日
30. Noise 処理(ランダムな円の描画)
中略
size(500, 300)
strokewidth(0.5)
stroke(0, 0, 0, 0.8)
centx = WIDTH/2
centy = HEIGHT/2
for i in range(100):
lastx = -999
lasty = -999
radius = 10
radiusnoise = random()
startangle = random(360)
endangle = 1440 + random(1440)
anglestep = 5 + random(3)
for ang in range(startangle, endangle, anglestep):
radiusnoise += 0.05
radius += 0.5
n_radius = radius +
(noise.generate(radiusnoise) * 200) - 100
rad = radians(ang)
x = centx + (n_radius * cos(rad))
y = centy + (n_radius * sin(rad))
if (lastx > -999):
line(x, y, lastx, lasty)
lastx = x
lasty = y
ランダムな螺旋を100回繰り返し描画
13年9月15日日曜日
39. 群衆アルゴリズム(Boids)
size(300, 200)
for i in range(100):
x = random(WIDTH)
y = random(HEIGHT)
r = random(10)
oval(x, y, r, r)
まずはランダムに円を描いてみる
(x, y)
r1
r2
13年9月15日日曜日
40. 群衆アルゴリズム(Boids)
中略
class Circle:
def __init__(self, x, y, r):
self.x = x
self.y = y
self.cx = x + (r / 2.0)
self.cy = y + (r / 2.0)
self.r = r
self.c = color(random(), random(),
random(), 0.3)
def draw(self):
fill(self.c)
oval(self.x, self.y, r, r)
for i in range(50):
x = random(WIDTH)
y = random(HEIGHT)
r = random(30)
circle = Circle(x, y, r)
circle.draw()
まずはランダムに円を描いてみる その2
管理しやすいようにCircle クラスを作成
(x, y)
r1
r
(cx,cy)
13年9月15日日曜日
41. 群衆アルゴリズム(Boids)
class Circle:
def __init__(self, x, y, r, d_x, d_y):
self.x = x
self.y = y
self.cx = x + (r / 2.0)
self.cy = y + (r / 2.0)
self.r = r
self.c = color(random(), random(), random(), 0.3)
self.d_x = d_x
self.d_y = d_y
def draw(self):
fill(self.c)
oval(self.x, self.y, self.r, self.r)
def update(self):
self.x += self.d_x
self.y += self.d_y
self.cx = self.x + (r/2.0)
self.cy = self.y + (r/2.0)
ランダムに円を動かしてみる
Circleに速度を追加する
updateでx座標、y座標を速度の分だけ更新
dx
dy
13年9月15日日曜日
42. 群衆アルゴリズム(Boids)
speed(30)
def setup():
global circles
circles = []
for i in range(50):
x = random(WIDTH)
y = random(HEIGHT)
r = random(30)
d_x = random(-5, 5)
d_y = random(-5, 5)
circle = Circle(x, y, r, d_x, d_y)
circles.append(circle)
def draw():
global circles
for circle in circles:
circle.draw()
circle.update()
1. 初期化時にcircleを作成し、配列に格納
2. 毎フレーム毎にcircleを描画
3. 描画に各circle毎にx座標、y座標を更新
13年9月15日日曜日