2007. 6. 20. 19:10
Code/NodeBox
from math import cos, sin, radians
class Particle:
def __init__(self, x, y, vx, vy,a):
self.x=x
self.y=y
self.vx=vx
self.vy=vy
self.a=a
def dynamics(self):
c=0.001
r=1.1
ax=-self.vx*c
ay=-self.vy*c
self.vx+=ax
self.vy+=ay
self.x+=self.vx
self.y+=self.vy
if (self.x>=WIDTH):
self.vx*=-r
self.x=WIDTH
if (self.x<=0):
self.vx*=-r
self.x=0
if (self.y>=HEIGHT):
self.vy*=-r
self.y=HEIGHT
if (self.y<=0):
self.vy*=-r
self.y=0
def oval(self):
self.a+=10
oval(self.x-30+100*cos(radians(self.a)), self.y+30-100*sin(radians(self.a)), 20, 20)
def rect(self):
rect(self.x-30, self.y+30, 30, 30)
size(300,300)
speed(100)
def setup():
global ping
ping=range(5)
for i in range(5):
ping[i]=Particle(i*20+150, i*20+150, i*5+2, i*5+1, 0)
def draw():
global ping
for i in ping:
i.dynamics()
i.oval()
i.rect()
class Particle:
def __init__(self, x, y, vx, vy,a):
self.x=x
self.y=y
self.vx=vx
self.vy=vy
self.a=a
def dynamics(self):
c=0.001
r=1.1
ax=-self.vx*c
ay=-self.vy*c
self.vx+=ax
self.vy+=ay
self.x+=self.vx
self.y+=self.vy
if (self.x>=WIDTH):
self.vx*=-r
self.x=WIDTH
if (self.x<=0):
self.vx*=-r
self.x=0
if (self.y>=HEIGHT):
self.vy*=-r
self.y=HEIGHT
if (self.y<=0):
self.vy*=-r
self.y=0
def oval(self):
self.a+=10
oval(self.x-30+100*cos(radians(self.a)), self.y+30-100*sin(radians(self.a)), 20, 20)
def rect(self):
rect(self.x-30, self.y+30, 30, 30)
size(300,300)
speed(100)
def setup():
global ping
ping=range(5)
for i in range(5):
ping[i]=Particle(i*20+150, i*20+150, i*5+2, i*5+1, 0)
def draw():
global ping
for i in ping:
i.dynamics()
i.oval()
i.rect()
'Code > NodeBox' 카테고리의 다른 글
arrive (0) | 2007.06.25 |
---|---|
steering (0) | 2007.06.25 |
orbit (0) | 2007.06.20 |
particle(rect+oval)_class (0) | 2007.06.20 |
ping_class (0) | 2007.06.20 |