Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- myCircle ball;
- void setup(){
- size(200, 200);
- ellipseMode(CENTER);
- fill(255);
- ball = new myCircle(width / 4, height / 2, 1, 1, width/20, 1.05);
- }
- void draw(){
- background(0);
- ball.display();
- }
- class myCircle{
- int xDir, yDir;
- float speed, diam, xPos, yPos;
- myCircle(float x, float y, int xDir, int yDir, float dia, float velocity){
- xPos = x;
- yPos = y;
- this.xDir = xDir;
- this.yDir = yDir;
- diam = dia;
- speed = velocity;
- }
- void display(){
- if(xPos <= 0 + (diam/2) || xPos >= width - (diam/2)){
- xDir *= -1;
- }
- if(yPos - (diam/2)<= 0 || yPos >= height - (diam/2)){
- yDir *= -1;
- }
- xPos += speed * xDir;
- yPos += speed * yDir;
- ellipse(xPos, yPos, diam, diam);
- }
- }
Add Comment
Please, Sign In to add comment