블로그 이미지
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. 7. 13. 17:52 Code/NodeBox
사용자 삽입 이미지
Splash를 여러 개 만들기.
초기 위치와  터지는 위치를 설정하여 여러 개의 물방울을 만들자.

from math import sin, cos, radians

def ovalc(cx, cy, w, h):
    x = cx-w/2
    y = cy-h/2
    oval(x, y, w, h)

class Splash:
    def __init__(self,x,y,p):
        self.f = 0
        self.x = x
        self.y = y
        self.p = p

        self.d = range(6)
        self.hit = 0
            
    def fall(self):
        self.f += 1
        
        if self.y <= self.p:
            self.y = self.f*10        
            ovalc(self.x, self.y, 20, 20)


        if (self.y > self.p) & (self.hit==0):
            for i in range(6):
                self.d[i] = Drop(self.x,self.p,i*60)
                    
            self.hit = 1
        
        if self.hit==1:
            for i in range(6):
                k = self.d[i]
                k.scatter()

            
class Drop:       
    def __init__(self,x,p,a):
        self.f = 0
        self.x = x
        self.p = p
        self.a = a
        
    def scatter(self):
        r = 2*self.f
        self.f += 1
        a = self.a
        
        x = self.x + r*cos(radians(a))
        y = self.p + r*sin(radians(a))             
 
        ovalc(x, y, 10, 10)

size(300,300)
speed(150)

def setup():
    global c
    global c0
    global c1
    global c2
    global c3
    global c4
 
    c = range(5)   
    c[0] = Splash(50,0,100)
    c[1] = Splash(100,0,250)
    c[2] = Splash(150,0,150)
    c[3] = Splash(200,0,100)
    c[4] = Splash(250,0,200)
    
    c0 = c[0]
    c1 = c[1]
    c2 = c[2]
    c3 = c[3]
    c4 = c[4]
    
def draw():
    global c
    global c0
    global c1
    global c2
    global c3
    global c4
   
    c0.fall()
    c1.fall()
    c2.fall()
    c3.fall()
    c4.fall()

Drop 클래스의 self.x 와 self.y 는 Splash 클래스의 것들과 다르다.
메쏘드 fall에서 Drop 클래스의 인스턴스를 생성할 때 인수를 클래스 멤버로 입력하면, 결과적으로 다른 클래스의 멤버에 접근할 수 있게 된다.

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

David Hirmes - lines02  (0) 2007.07.25
David Hirmes - blobs01  (0) 2007.07.18
splash_class  (0) 2007.07.13
progress_class  (0) 2007.07.12
popping_1.1  (0) 2007.07.09
posted by maetel