블로그 이미지
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. 16:40 Code/NodeBox
splash 예제를 두 개의 class를 써서 코딩하기

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):
        self.f = 0
        self.x = 0
        self.y = 0

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


        if (self.y > HEIGHT/2) & (self.hit==0):
            for i in range(6):
                self.d[i] = Drop(i*60)
                    
            self.hit = 1
        
        if self.hit==1:
            for i in range(6):
                ttt=self.d[i]
                ttt.scatter()
 
            
class Drop:       
    def __init__(self,a):
        self.f = 0
        self.a = a
        
    def scatter(self):
        r = 2*self.f
        self.f += 1
        a = self.a
        
        x = WIDTH/2 + r*cos(radians(a))
        y = HEIGHT/2 + r*sin(radians(a))             
 
        ovalc(x, y, 10, 10)


size(300,300)
speed(150)

def setup():
    global c    
    c = Splash()
    
def draw():
    global c
    c.fall()

lesson 1. class를 range 변수로 선언하는 것이 가능하다. (class member를 range의 순차번호를 매개로 했다.)
lesson 2. 어떠한 사건이 일어난 첫순간을 인식하여 사용할 때 쓰이는 pattern을 배웠다. (상기 코드의 self.hit 변수)

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

David Hirmes - blobs01  (0) 2007.07.18
splash_class_multi  (0) 2007.07.13
progress_class  (0) 2007.07.12
popping_1.1  (0) 2007.07.09
popping_1.0 (수정 중)  (0) 2007.07.06
posted by maetel