블로그 이미지
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 31
  • total
  • today
  • yesterday

Category

'instance'에 해당되는 글 2건

  1. 2008.04.14 Class와 Object
  2. 2007.07.13 splash_class_multi
2008. 4. 14. 15:47 @GSMC/정문열: Generative Art
Head First Java 개정판
68쪽

인스턴스 변수 - 객체에서 자신에 대해 아는 것 (상태)
메소드 - 객체에서 자신이 하는 것 (행동)

인스턴스 변수 - 객체의 상태 - 데이터

"인스턴스(instance)란 객체(object)를 부르는 다른 이름이라고 생각하세요."

정 교수님:
C에서의 new와 Java에서의 new는 다르다.
C에서의 new는 memory를 allocate하는 데 반해,
Java에서의 new는 class의 constructor를 선언하는 것이다.

75쪽
자바 애플리케이션에서는 여러 클래스 가운데 한 클래스에 main 메소드가 있어야 한다. 그리고 그 클래스를 통해서 프로그램을 시작하게 된다.

클래스는 해당 클래스 유형의 객체를 만드는 방법을 설명하는 역할을 한다.



http://java.sun.com/javase/6/docs/api/java/lang/reflect/Array.html

http://java.sun.com/javase/6/docs/api/java/lang/Integer.html
noah:
Java에는 두 가지 종류의 int가 있다. 하나는 C에서와 같은 primitive 유형이고 다른 하나는 java.lang.Number를 상속하는 클래스 유형의 int이다.


'@GSMC > 정문열: Generative Art' 카테고리의 다른 글

변수  (0) 2008.05.17
class 5/1  (0) 2008.05.01
[이선애] study 1  (0) 2008.03.28
class 3/27  (0) 2008.03.27
tree (data structure)  (0) 2008.03.24
posted by maetel
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