ProcessingのPython版「NodeBox」で色々してみたい(゚Д゚)p
クラスとか
NodeBoxチュートリアルのStrategy Classes あたりをやってみた。
exampleを流用、若干変更。
できあがり
mosquito, worm & ant
ゆっくり、ゆらゆら、たくさんとかやりたいんだけど...(||゚Д゚)
code
size(300, 210) speed(10) 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 mosquito = Creature(WIDTH/2, HEIGHT/2, speed=2.0) worm = Creature(WIDTH/2, HEIGHT/2, speed=0.5, size=5) ant = Creature(WIDTH/2, HEIGHT/2, speed=0.5, size=4) def draw(): mosquito.roam() mosquito.speed = random(0.5, 15.0) oval(mosquito.x, mosquito.y, mosquito.size, mosquito.size) for i in range(10): worm.roam() worm.speed = random(0.01, 3.5) oval(worm.x, worm.y, worm.size, worm.size) ant.roam() ant.speed = random(0.0, 3.0) oval(ant.x, ant.y, ant.size, ant.size)