알쓰모쓰(알면 아는 대로 쓰고, 모르면 모르는 대로 쓴다)/프로세싱
프로세싱, 공 움직임
다준
2018. 8. 15. 13:07
// Ball Position
int xPos;
// Ball Direction
int xDir;
void setup(){
size(300, 200);
xPos = 0;
xDir = 1;
}
void draw(){
background(128);
//Ball Drawing and Movement
ellipse(xPos, 10, 20, 20);
xPos = xPos + xDir;
// Ball Bouncing
if ( xPos < 0) xDir = xDir * -1;
if ( xPos > width) xDir = xDir *= -1;
}