팩맨 예제 |
|||||
---|---|---|---|---|---|
작성자 | 김용남 | 등록일 | 21.07.27 | 조회수 | 70 |
int x1 = int(random(width)); int y1 = int(random(height));
int x2 = int(random(width)); int y2 = int(random(height));
int xspeed1 = 2; int yspeed1 = 1;
int xspeed2 = 1; int yspeed2 = 2;
int size = 50; int mouthtime = 0;
float distance = 0.0;
void setup(){ size(640, 480); }
void draw(){ println(frameCount); background(0);
distance = dist(x1, y1, x2, y2); if(distance < size){ xspeed1 = 0; yspeed1 = 0; xspeed2 = 0; yspeed2 = 0; size = 0; }
fill(random(255), random(255), random(255)); // random(5);
if(frameCount % 60 < 30){ arc(x1, y1, size, size, 0.5, 5.78); } else { arc(x1, y1, size, size, 0.1, 6.18); }
if(frameCount % 60 < 30){ arc(x2, y2, size, size, 0.1, 6.18); } else { arc(x2, y2, size, size, 0.5, 5.78); }
x1 = x1 + xspeed1; y1 = y1 + yspeed1;
x2 = x2 + xspeed2; y2 = y2 + yspeed2;
if(x1 < 0 || x1 > 640){ xspeed1 = -xspeed1; } if(y1 < 0 || y1 > 480){ yspeed1 = -yspeed1; }
if(x2 < 0 || x2 > 640){ xspeed2 = -xspeed2; } if(y2 < 0 || y2 > 480){ yspeed2 = -yspeed2; } }
void mousePressed(){ x1 = int(random(width)); y1 = int(random(height));
x2 = int(random(width)); y2 = int(random(height));
xspeed1 = int(random(10)); yspeed1 = int(random(10));
xspeed2 = int(random(10)); yspeed2 = int(random(10));
size = 50; } |
이전글 | 몬드리안 실습 |
---|---|
다음글 | 몬드리안 |