Code/NodeBox

matrix_color_chain

maetel 2007. 6. 27. 18:54


size(200,200)
speed(100)

def setup():
    global x
    global y
    global f
    global c
    global n
    global f
   
    f=0
    n=0
       
    c=range(16) #color of a cell
    n=range(16)
    for cell in range(16): #cell number
        c[cell]=1
        n[cell]=0
       
def draw():
    global x
    global y
    global f
    global c
    global n

    f+=1 #frame
    x=MOUSEX
    y=MOUSEY   
    s=50 #size of a cell   
    b=1 #blue
 
 
    for cell in range(16):
        c[cell]-=0.05-0.01*n[cell]
#        c[cell]+=0.027*n[cell]
   
    for h in range(4):
        for w in range(4):
            cell=h*4+w #cell number
            pl=0
            pr=0
            pt=0
            pb=0
            if ((x>=w*s)&(x<=(w+1)*s)) & ((y>=h*s)&(y<=(h+1)*s)):
                c[cell]=1

            if w>0:
                if (c[cell]<c[cell-1]):
                    pl=1       
            if w<3:   
                if (c[cell]<c[cell+1]):
                    pr=1
            if h>0:
                if (c[cell]<c[cell-4]):
                    pt=1
            if h<3:
                if (c[cell]<c[cell+4]):
                    pb=1                                      
           
            n[cell]=pl+pr+pt+pb
           
            fill(c[cell],c[cell],b)
            stroke(1)
            rect(w*s,h*s,s,s)
           
           
## lesson 1. range 변수의 매개변수들은 모두 range여야 한다.