xxxxxxxxxx
Ball myBall;
void setup(){
size(300, 300);
smooth();
myBall= new Ball();
//rounds out your circle a little bit, helps "alias" it.lessjagged
}
void draw(){
background (0);
myBall.display();
myBall.move();
myBall.change();
//triangle
fill(#00E0B9);
triangle(200, 200, 200, 300, 300, 300);
//blue vertical line
strokeWeight(3);
stroke(0, 0, 140);
line(width/3, 0, width/3, height);
//blue vertical line
strokeWeight(3);
stroke(0, 0, 140);
line(200, 0, 200, height);
//red horizontal line
strokeWeight(3);
stroke(100, 0, 0);
line(0, 100, width, 100);
//red horizontal line
strokeWeight(3);
stroke(100, 0, 0);
line(0, 200, width, 200);
//ellipse
strokeWeight(2);
fill(0);
stroke(#FFD012);
ellipse (100, 100, mouseX, mouseY);
}
class Ball{
float x;
float y;
float xspeed= 5;
float yspeed= 5;
float gravity = 0.2;
color c=#00E0B9;
void display(){
//Ball draw
fill(c);
noStroke();
ellipse (x, y, 50, 50);
}
void change(){
if (x>100 && x<200)
{c=255;}
else {c=#00E0B9;}
// if (x>200)
//{fill(#00E0B9);}
}
void move(){
x = x + xspeed;
y= y + yspeed;
if (x>width || x<=0)
{ xspeed=-xspeed;}
if (y >height || y<=0)
{yspeed = - yspeed;} else
{yspeed=yspeed + gravity; }
}
}