프로세싱 튀는 공 |
|||||
---|---|---|---|---|---|
작성자 | 김용남 | 등록일 | 19.08.29 | 조회수 | 79 |
Ball[] myBall=new Ball[0]; void setup(){ size(300,300); } void draw(){ background(255); for(int i=0; i<=myBall.length-1; i++){ myBall[i].move(); myBall[i].bounce(); myBall[i].display(); } } void mousePressed(){ Ball aBall=new Ball(random(30,60),random(30,270),random(30,270),random(-5,5),random(-5,5)); myBall=(Ball[])append(myBall,aBall); } class Ball{ float x; float y; float r; float xspeed; float yspeed; Ball(float radiation, float tempX,float tempY,float tempXSpeed,float tempYSpeed){ r=radiation; x=tempX; y=tempY; xspeed=tempXSpeed; yspeed=tempYSpeed; } void move(){ x+=xspeed; y+=yspeed; } void bounce(){ if(x<r/2||x>300-r/2){ xspeed*=-1; } if(y<r/2||y>300-r/2){ yspeed*=-1; } } void display(){ stroke(255); fill(175); circle(x,y,r); } }
|
이전글 | FloorPlanner 활용 |
---|---|
다음글 | 프로세싱 따라다니는 점 |