블로그 이미지
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

'Code'에 해당되는 글 41건

  1. 2007.06.20 orbit
  2. 2007.06.20 particle(rect+oval)_class
  3. 2007.06.20 ping_class
  4. 2007.06.18 ping_multi
  5. 2007.06.18 ping
  6. 2007.06.17 splash
  7. 2007.06.14 progress
  8. 2007.06.14 range()
  9. 2007.04.27 array
  10. 2007.04.20 noise()
  11. 2007.04.19 constrain
  12. 2007.02.26 The Nature of Code - Forces
  13. 2006.12.25 UNIX 기본 명령어
  14. 2006.12.25 PATH variable
  15. 2006.08.11 stair
  16. 2006.06.19 clock
2007. 6. 20. 19:07 Code/NodeBox

size(200,200)
speed(100)

from math import cos, sin, radians

def setup():
    global a    
    a=0
        
def draw():
    global a
    
    r=100
    a+=10
    oval(100+r*cos(radians(a)), 100+r*sin(radians(a)), 10, 10)


   

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

steering  (0) 2007.06.25
ping_orbit  (0) 2007.06.20
particle(rect+oval)_class  (0) 2007.06.20
ping_class  (0) 2007.06.20
ping_multi  (0) 2007.06.18
posted by maetel
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
2007. 6. 20. 12:01 Code/NodeBox
class를 사용하여 ping_multi 코딩하기

class Ping:
    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)
   
       
size(300,300)
speed(100)   
   
def setup():
    global particle
   
    particle=range(5)
    for i in range(5):
        particle[i]=Ping(i*20+150,i*5+150,i*5+1, i*5+1)
        #print particle[i]
   
       
def draw():
    global particle
           
    for i in particle:
        print i
        i.render()


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

orbit  (0) 2007.06.20
particle(rect+oval)_class  (0) 2007.06.20
ping_multi  (0) 2007.06.18
ping  (0) 2007.06.18
splash  (0) 2007.06.17
posted by maetel
2007. 6. 18. 16:03 Code/NodeBox

size(300,300)
speed(100)

def setup():
    global x
    global y
    global vx
    global vy

#initial position
    x=range(5)
    y=range(5)
    
    x[0]=150  
    y[0]=150

    x[1]=100
    y[1]=100
    
    x[2]=200
    y[2]=200
    
    x[3]=100
    y[3]=200
    
    x[4]=200
    y[4]=100
    
#initial velocity
    vx=range(5)
    vy=range(5)
    
    vx[0]=20
    vy[0]=20
    
    vx[1]=10
    vy[1]=20
    
    vx[2]=20
    vy[2]=10
    
    vx[3]=10
    vy[3]=10
    
    vx[4]=5
    vy[4]=25
    
        
def draw():
    global x
    global y
    global vx    
    global vy
    
    c=0.001  #viscosity
    r=1.1   #repulsive force

    ax=range(5)
    ay=range(5)    
    
    for num in range(5):
        ax[num]=-vx[num]*c
        ay[num]=-vy[num]*c
        vx[num]+=ax[num]    
        vy[num]+=ay[num]
        x[num]+=vx[num]
        y[num]+=vy[num]
          
        if (x[num]>=WIDTH-5):
            vx[num]*=-r
            x[num]=WIDTH-5

        if (x[num]<=5):
            vx[num]*=-r
            x[num]=0

        if (y[num]>=HEIGHT-5):
            vy[num]*=-r
            y[num]=HEIGHT-5

        if (y[num]<=5):
            vy[num]*=-r
            y[num]=0    

        oval(x[num],y[num],20,20)
 

    #print x,y,vx,vy                
    #text(str(y),100,100)


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

particle(rect+oval)_class  (0) 2007.06.20
ping_class  (0) 2007.06.20
ping  (0) 2007.06.18
splash  (0) 2007.06.17
progress  (0) 2007.06.14
posted by maetel
2007. 6. 18. 01:32 Code/NodeBox

size(300,300)
speed(100)

def setup():
    global x
    global y
    global vx
    global vy
    
    x=150   #initial position
    y=150
    vx=10   #initial velocity
    vy=15
    
    
def draw():
    global x
    global y
    global vx
    global vy
    
    c=0.01  #viscosity
    r=1.1   #repulsive force
    
    ax=-vx*c
    ay=-vy*c
    vx+=ax
    vy+=ay
    x+=vx
    y+=vy

 
     
    if (x>WIDTH):
        vx*=-r
        x=WIDTH

    if (x<0):
        vx*=-r
        x=0

    if (y>HEIGHT):
        vy*=-r
        y=HEIGHT    

    if (y<0):
        vy*=-r
        y=0    

    oval(x,y,20,20) 

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

ping_class  (0) 2007.06.20
ping_multi  (0) 2007.06.18
splash  (0) 2007.06.17
progress  (0) 2007.06.14
range()  (0) 2007.06.14
posted by maetel
2007. 6. 17. 21:44 Code/NodeBox


size(300,300)
speed(150)

def setup():
    global frame
    global r

    frame = 0
    r=0

def draw():   
    global frame
    global r
    from math import sin, cos, radians

    frame += 1   
    y=frame*10
    x=WIDTH/2
           
    if y>=HEIGHT/2:
        r+=2
# 1)
        for a in range(0,12):
            ovalcen(x+r*cos(radians(a*30)), HEIGHT/2+r*sin(radians(a*30)), 10, 10)
# 2)
#        a=0           
#        while a<360:
#            a+=60
#            ovalcen(x+r*cos(radians(a)), HEIGHT/2+r*sin(radians(a)), 10, 10)
    else:
        fill(0,0,0)
        ovalcen(x, y, 20, 20)
           
    if r>=200:
        frame=0
        r=0
           
def ovalcen(cx,cy,w,h):
    x=cx-w/2
    y=cy-h/2
    oval(x,y,w,h)

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

ping_class  (0) 2007.06.20
ping_multi  (0) 2007.06.18
ping  (0) 2007.06.18
progress  (0) 2007.06.14
range()  (0) 2007.06.14
posted by maetel
2007. 6. 14. 18:18 Code/NodeBox


size(200,200)
speed(20)

def setup():
    global frame
    global y
    
    frame = 0
    y=0
     
     
def draw():    
    global frame
    global y
    
    frame += 1
    x=frame*10

    fill(0,0,0)
    rect (x, y, 10, 10)
            
    if x>WIDTH:
        frame=0
        y += 50
    if y>HEIGHT:
        frame=0    
        y=0  

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

ping_class  (0) 2007.06.20
ping_multi  (0) 2007.06.18
ping  (0) 2007.06.18
splash  (0) 2007.06.17
range()  (0) 2007.06.14
posted by maetel
2007. 6. 14. 16:26 Code/NodeBox
사용자 삽입 이미지

#1
for x in range(10):
    for y in range(10-x):        
        rect(x*10, y*10+10*x, 5, 5)


#2
for x in range(11):
    for y in range(11):
        if x<y:
            rect(x*10, y*10-10, 5, 5)      

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

ping_class  (0) 2007.06.20
ping_multi  (0) 2007.06.18
ping  (0) 2007.06.18
splash  (0) 2007.06.17
progress  (0) 2007.06.14
posted by maetel
2007. 4. 27. 22:58 Code

'Code' 카테고리의 다른 글

The Nature of Code - Forces  (0) 2007.02.26
UNIX 기본 명령어  (0) 2006.12.25
PATH variable  (0) 2006.12.25
posted by maetel
2007. 4. 20. 23:04 Code/Java
processing의 noise() 함수의 자바 소스코드가 궁금하다.

noise()
Perlin noise is a random sequence generator producing a more natural ordered, harmonic succession of numbers compared to the standard random() function. It was invented by Ken Perlin in the 1980s and been used since in graphical applications to produce procedural textures, natural motion, shapes, terrains etc.
 

 // PERLIN NOISE

  // [toxi 040903]
  // octaves and amplitude amount per octave are now user controlled
  // via the noiseDetail() function.

  // [toxi 030902]
  // cleaned up code and now using bagel's cosine table to speed up

  // [toxi 030901]
  // implementation by the german demo group farbrausch
  // as used in their demo "art": http://www.farb-rausch.de/fr010src.zip

  static final int PERLIN_YWRAPB = 4;
  static final int PERLIN_YWRAP = 1<<PERLIN_YWRAPB;
  static final int PERLIN_ZWRAPB = 8;
  static final int PERLIN_ZWRAP = 1<<PERLIN_ZWRAPB;
  static final int PERLIN_SIZE = 4095;

  int perlin_octaves = 4; // default to medium smooth
  float perlin_amp_falloff = 0.5f; // 50% reduction/octave

  // [toxi 031112]
  // new vars needed due to recent change of cos table in PGraphics
  int perlin_TWOPI, perlin_PI;
  float[] perlin_cosTable;
  float[] perlin;

  Random perlinRandom;


  /**
   * Computes the Perlin noise function value at point x.
   */
  public float noise(float x) {
    // is this legit? it's a dumb way to do it (but repair it later)
    return noise(x, 0f, 0f);
  }

  /**
   * Computes the Perlin noise function value at the point x, y.
   */
  public float noise(float x, float y) {
    return noise(x, y, 0f);
  }

  /**
   * Computes the Perlin noise function value at x, y, z.
   */
  public float noise(float x, float y, float z) {
    if (perlin == null) {
      if (perlinRandom == null) {
        perlinRandom = new Random();
      }
      perlin = new float[PERLIN_SIZE + 1];
      for (int i = 0; i < PERLIN_SIZE + 1; i++) {
        perlin[i] = perlinRandom.nextFloat(); //(float)Math.random();
      }
      // [toxi 031112]
      // noise broke due to recent change of cos table in PGraphics
      // this will take care of it
      perlin_cosTable = PGraphics.cosLUT;
      perlin_TWOPI = perlin_PI = PGraphics.SINCOS_LENGTH;
      perlin_PI >>= 1;
    }

    if (x<0) x=-x;
    if (y<0) y=-y;
    if (z<0) z=-z;

    int xi=(int)x, yi=(int)y, zi=(int)z;
    float xf = (float)(x-xi);
    float yf = (float)(y-yi);
    float zf = (float)(z-zi);
    float rxf, ryf;

    float r=0;
    float ampl=0.5f;

    float n1,n2,n3;

    for (int i=0; i<perlin_octaves; i++) {
      int of=xi+(yi<<PERLIN_YWRAPB)+(zi<<PERLIN_ZWRAPB);

      rxf=noise_fsc(xf);
      ryf=noise_fsc(yf);

      n1  = perlin[of&PERLIN_SIZE];
      n1 += rxf*(perlin[(of+1)&PERLIN_SIZE]-n1);
      n2  = perlin[(of+PERLIN_YWRAP)&PERLIN_SIZE];
      n2 += rxf*(perlin[(of+PERLIN_YWRAP+1)&PERLIN_SIZE]-n2);
      n1 += ryf*(n2-n1);

      of += PERLIN_ZWRAP;
      n2  = perlin[of&PERLIN_SIZE];
      n2 += rxf*(perlin[(of+1)&PERLIN_SIZE]-n2);
      n3  = perlin[(of+PERLIN_YWRAP)&PERLIN_SIZE];
      n3 += rxf*(perlin[(of+PERLIN_YWRAP+1)&PERLIN_SIZE]-n3);
      n2 += ryf*(n3-n2);

      n1 += noise_fsc(zf)*(n2-n1);

      r += n1*ampl;
      ampl *= perlin_amp_falloff;
      xi<<=1; xf*=2;
      yi<<=1; yf*=2;
      zi<<=1; zf*=2;

      if (xf>=1.0f) { xi++; xf--; }
      if (yf>=1.0f) { yi++; yf--; }
      if (zf>=1.0f) { zi++; zf--; }
    }
    return r;
  }

  // [toxi 031112]
  // now adjusts to the size of the cosLUT used via
  // the new variables, defined above
  private float noise_fsc(float i) {
    // using bagel's cosine table instead
    return 0.5f*(1.0f-perlin_cosTable[(int)(i*perlin_PI)%perlin_TWOPI]);
  }

  // [toxi 040903]
  // make perlin noise quality user controlled to allow
  // for different levels of detail. lower values will produce
  // smoother results as higher octaves are surpressed

  public void noiseDetail(int lod) {
    if (lod>0) perlin_octaves=lod;
  }

  public void noiseDetail(int lod, float falloff) {
    if (lod>0) perlin_octaves=lod;
    if (falloff>0) perlin_amp_falloff=falloff;
  }

  public void noiseSeed(long what) {
    if (perlinRandom == null) perlinRandom = new Random();
    perlinRandom.setSeed(what);
    // force table reset after changing the random number seed [0122]
    perlin = null;
  }

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

constrain  (0) 2007.04.19
posted by maetel
2007. 4. 19. 00:17 Code/Java
constrain

ref. http://dev.processing.org/reference/everything/

View of /trunk/processing/core/src/processing/core/PApplet.java

constrain(float, float, float) - Static method in class processing.core.

public static final float constrain(float amt, float low, float high)

static public final float constrain(float amt, float low, float high) {
   return (amt < low) ? low : ((amt > high) ? high : amt);
 }



constrain(int, int, int) - Static method in class processing.core.

public static final int constrain(int amt, int low, int high)

  static public final int constrain(int amt, int low, int high) {
   return (amt < low) ? low : ((amt > high) ? high : amt);
 }


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

noise()  (0) 2007.04.20
posted by maetel
2007. 2. 26. 00:13 Code
The Nature of Code - Forces

2007-02-25 @홍대 앞 잔디와 소나무: 믿음

class

'Code' 카테고리의 다른 글

array  (0) 2007.04.27
UNIX 기본 명령어  (0) 2006.12.25
PATH variable  (0) 2006.12.25
posted by maetel
2006. 12. 25. 18:54 Code
ls - file listing (윈도우/도스의 dir에 해당)
cp - copy
mv - move
rm - remove

'Code' 카테고리의 다른 글

array  (0) 2007.04.27
The Nature of Code - Forces  (0) 2007.02.26
PATH variable  (0) 2006.12.25
posted by maetel
2006. 12. 25. 18:44 Code
Update the PATH variable

Start > Control Panel > System (classic view) > Advanced > Environment Variables 에 들어가서 '사용자 변수'(현재 사용자에게만 적용. '시스템 변수'는 모든 사용자에게 적용)에 편집 버튼을 누르고 ;을 추가한 후 경로를 입력한다.

'Code' 카테고리의 다른 글

array  (0) 2007.04.27
The Nature of Code - Forces  (0) 2007.02.26
UNIX 기본 명령어  (0) 2006.12.25
posted by maetel
2006. 8. 11. 20:31 Code/Processing
assignment from chang -


my work:
void setup(){
  size(600,600);
  background(100);
  frameRate(4);
}

void draw(){
  translate(20,20);
  noStroke();
  for(int x=0; x<11; x+=1){
    for(int y=x; y<11; y+=1) {
      fill(255-random(60),150+random(-20,20),200+random(-10,10));
      rect(10+50*x, 10+50*y, 40,40);
    }
  }
}

one cut:
사용자 삽입 이미지

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

simple wave test  (0) 2007.08.30
clock  (0) 2006.06.19
posted by maetel
2006. 6. 19. 20:58 Code/Processing
내가 처음 짜 보는 코드!
코드도 버전을 업그레이드 해 가며, 단순하게 출발해서 진화해 갈 수 있다는 것을 배움.
우선 visualization에 급급해 미감을 세울 여지가 없다는 것이 아쉽다.
처음인데 뭘 바래. ㅋㅋ


아날로그 시계 시분초침 만들기:
clock_a01

//define the variables of the time values
int s;
int h;
int m;

//define the constants of the length of the niddle
int rs=50;
int rm=130;
int rh=90;

//define the variables of angle of the niddle
float as;
float am;
float ah;


void setup(){
  size(400,400,P3D);
 
}

void draw(){
  translate(width/2, height/2);
  background(255);
  s=second();
  m=minute();
  h=hour();

  as=TWO_PI/60*s;
  am=TWO_PI/60*m;
  ah=TWO_PI/12*h+PI/360*m;

  ellipse(0,0,300,300);
  line(0,0, rs*cos(as-PI/2), rs*sin(as-PI/2));
  line(0,0, rm*cos(am-PI/2), rm*sin(am-PI/2));
  line(0,0, rh*cos(ah-PI/2), rh*sin(ah-PI/2));

println(h + ":" + m + ":" + s);
}


초침 변경:
click_a02

//colors as seconds

//define the variables of the time values
int s;
int m;
int h;

//define the constants of the length of the niddle
int rs=50;
int rm=130;
int rh=90;

//define the variables of angle of the niddle
float as;
float am;
float ah;

//define the angle of the color arcs
float cs;

void setup(){
  size(400,400);3
  smooth();
}

void draw(){
  //  translate(width/2, height/2);
  background(255);

  s=second();
  m=minute();
  h=hour();

  as=TWO_PI/60*s;
  am=TWO_PI/60*m;
  ah=TWO_PI/12*h+PI/360*m;

  cs = (PI/30*s)+(PI*3/2);
  int crs=255-(3*s);
  int cgs=255/60*s;
  int cbs=3*s;

  strokeWeight(8);
  //  noStroke();
  //  fill(126,80);
  noFill ();
  ellipse(200,200,300,300);

  noStroke();
  fill(crs,cgs,cbs);
  ellipse(200,200,100,100);

  noStroke();
  fill(crs,cgs,cbs);
  arc(200,200,300,300,cs, cs+(PI/30));


  stroke (120);
  strokeWeight(1); 
  //  line(200,200, 200+rs*cos(as-PI/2), 200+rs*sin(as-PI/2));
  strokeWeight(3); 
  line(200,200, 200+rm*cos(am-PI/2), 200+rm*sin(am-PI/2));
  strokeWeight(6);   
  line(200,200, 200+rh*cos(ah-PI/2), 200+rh*sin(ah-PI/2));

  //  println(h + ":" + m + ":" + s);

}


마우스 버튼 인터랙션:
clock_a03

//reactive text

//define the variables of the time values
int s;
int m;
int h;

//define the constants of the length of the niddle
int rs=50;
int rm=130;
int rh=90;

//define the variables of angle of the niddle
float as;
float am;
float ah;

//define the angle of the color arcs
float cs;

PFont t;


void setup(){
  size(400,400);

  smooth();
  t=loadFont("APCCourier-Bold-48.vlw");
}

void draw(){
  //  translate(width/2, height/2);
  background(250);

  s=second();
  m=minute();
  h=hour();

  as=TWO_PI/60*s;
  am=TWO_PI/60*m;
  ah=TWO_PI/12*h+PI/360*m;

  cs = (PI/30*s)+(PI*3/2);
  int crs=255-(3*s);
  int cgs=255/60*s;
  int cbs=3*s;


  strokeWeight(8);
  //  noStroke();
  //  fill(126,80);
  noFill ();
  ellipse(200,200,300,300);

  noStroke();
  fill(crs,cgs,cbs);
  ellipse(200,200,100,100);

  noStroke();
  fill(crs,cgs,cbs);
  arc(200,200,300,300,cs, cs+(PI/30));


  stroke (120);
  strokeWeight(1); 
  //  line(200,200, 200+rs*cos(as-PI/2), 200+rs*sin(as-PI/2));
  strokeWeight(3); 
  line(200,200, 200+rm*cos(am-PI/2), 200+rm*sin(am-PI/2));
  strokeWeight(6);   
  line(200,200, 200+rh*cos(ah-PI/2), 200+rh*sin(ah-PI/2));

  //  println(h + ":" + m + ":" + s);
  if(mousePressed){
    background(crs,cgs,cbs);
    fill(255);
    textFont(t,40);
    String n=h + ":" + m ;
    text(n, mouseX-30,mouseY-5);

    textFont(t,80);
    String sec= "and "+ s;
    text(sec, 60, 220);
  }
}


색깔 조정 (하는 중) - frameRate와 random color의 문제: (아우 이거 해결 안 됨. ㅡㅜ)
clock_a04

//to adjust color changes

int s;
int m;
int h;

int rs=50;
int rm=130;
int rh=90;

float as;
float am;
float ah;

float cs;

PFont t;


void setup(){
  size(400,400);
  smooth();
  frameRate(1);
  smooth();
  t=loadFont("APCCourier-Bold-48.vlw");
}

void draw(){
  //  translate(width/2, height/2);
  background(250);

  s=second();
  m=minute();
  h=hour();

  as=TWO_PI/60*s;
  am=TWO_PI/60*m;
  ah=TWO_PI/12*h+PI/360*m;

  cs = (PI/30*s)+(PI*3/2);
  int crs=255-(3*s);
  int cgs=255/60*s;
  int cbs=3*s;

  float rr = random(255);
  float gr = random(255);
  float br = random(255);

  strokeWeight(8);
  //  noStroke();
  //  fill(126,80);
  noFill ();
  ellipse(200,200,300,300);

  noStroke();
  fill(rr,gr,br);
  ellipse(200,200,100,100);

  noStroke();
  fill(rr,gr,br);
  arc(200,200,300,300,cs, cs+(PI/30));


  stroke (120);
  strokeWeight(1); 
  //  line(200,200, 200+rs*cos(as-PI/2), 200+rs*sin(as-PI/2));
  strokeWeight(3); 
  line(200,200, 200+rm*cos(am-PI/2), 200+rm*sin(am-PI/2));
  strokeWeight(6);   
  line(200,200, 200+rh*cos(ah-PI/2), 200+rh*sin(ah-PI/2));

  //  println(h + ":" + m + ":" + s);
  if(mousePressed){
    background(rr,gr,br);
    fill(255);
    textFont(t,40);
    String n=h + ":" + m ;
    text(n, mouseX-30,mouseY-5);

    textFont(t,80);
    String sec= "and "+ s;
    text(sec, 60, 220);
  }


}



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

simple wave test  (0) 2007.08.30
stair  (0) 2006.08.11
posted by maetel