블로그 이미지
Leeway is... the freedom that someone has to take the action they want to or to change their plans.
maetel

Notice

Recent Post

Recent Comment

Recent Trackback

Archive

calendar

1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
  • total
  • today
  • yesterday

Category

2007. 6. 20. 18:08 Code/NodeBox
Compare a) with b).

a)
class Oval:
    def __init__(self, x, y, vx, vy):
        self.x=x
        self.y=y
        self.vx=vx
        self.vy=vy
        
    def render(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
                        
        oval(self.x, self.y, 20, 20)
            
class Rect:
    def __init__(self, x, y, vx, vy):
        self.x=x
        self.y=y
        self.vx=vx
        self.vy=vy
        
    def render(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

        rect(self.x,self.y, 25, 25)
                 
        
size(300,300)
speed(100)    
    
def setup():
    global ball
    global cell
    
    ball=range(5)
    cell=range(5)
    
    for i in range(5):
        ball[i]=Oval(i*20+150,i*5+150,i*5+1, i*5+1)
        cell[i]=Rect(i*25+50,i*25+150, i*5-1, i*5-1)    
        
def draw():
    global ball
    global cell
                
    for i in ball:
        i.render()
    
    for i in cell:
        i.render()

            
b)
class Particle:
    def __init__(self, x, y, vx, vy):
        self.x=x
        self.y=y
        self.vx=vx
        self.vy=vy
           
    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):
        oval(self.x+30, self.y-30, 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)
       
       
def draw():
    global ping
               
    for i in ping:
        i.dynamics()
        i.oval()
        i.rect()

           

                              

'Code > NodeBox' 카테고리의 다른 글

ping_orbit  (0) 2007.06.20
orbit  (0) 2007.06.20
ping_class  (0) 2007.06.20
ping_multi  (0) 2007.06.18
ping  (0) 2007.06.18
posted by maetel