# 本日のプロセッシング20「方向で」

＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊
＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊

ProcessingのPython版「NodeBox」で色々してみたい(ﾟДﾟ)p

NodeBoxチュートリアルSpecifics Math と以前やった Strategy Classes を参考にしてやってみた。

kyorokyoro

#### code

```from nodebox.geo import angle

size(300, 210)
speed(30)

class Creature:

def __init__(self, x, y, speed=1.0, size=2):
self.x = x
self.y = y
self.speed = speed
self.size = size

self._vx = 0
self._vy = 0

def roam(self):
v = self.speed
self._vx += random(-v, v)
self._vy += random(-v, v)
self._vx = max(-v, min(self._vx, v))
self._vy = max(-v, min(self._vy, v))

self.x += self._vx
self.y += self._vy

def setup():
global rove,x0,y0
rove = Creature(WIDTH/2, HEIGHT/2, speed=0, size=20)
x0 = rove.x
y0 = rove.y

def draw():
global rove,x0,y0

fill(0.5)
rect(0, 0, WIDTH, HEIGHT)

fill(0.8)
rove.roam()
rove.speed = random(0.3, 10.0)
oval(rove.x, rove.y, rove.size, rove.size)

a = angle(x0, y0, rove.x, rove.y)
transform(CORNER)
translate(rove.x + rove.size/2, rove.y + rove.size/2)
rotate(-a)
arrow(rove.size *2, 0, rove.size)
x0 = rove.x
y0 = rove.y
```