xxxxxxxxxx
float size2; //introduce size2 as a variable
myCircle c = new myCircle(50,50,1,15); //class myCircle is equivalent to c which is defined by new myCircle parameters
myCircle c2 = new myCircle(50,50,1.5,15); //class myCircle is equivalent to c2 which is defined by new myCircle parameters
void setup(){ //starting mode
c = new myCircle(50,50,1,15); //start with c which is a myCircle
size(200,200); //define canvas size
} //end void setup
void draw(){ //refreshing function box with list of functions to loop through
background(0); //background color
c.display(); //calling the display function from the class myCircle
c.move(); //calling the move function from the class myCircle
if(c.xpos > width){ //if statement (if the x position of the class myCircle is greater than the width of the canvas then...
c.getSmall(); //then c or myCircle's size gets half as small
c2.move();
} //end if statement
} //end void draw
class myCircle{ //the class for circles
float xpos; //possition of x
float ypos; //possition of y
float speed; //speed variable
float size; //circle size
float xdir = 1; //x direction
float ydir = 1; //y direction
myCircle(float tempx, float tempy, float tempspeed, float tempsize) { //introduce the circle's temparary variable fills to be referenced
xpos = tempx; //the possition of x is equal to the temparary possition of x
ypos = tempy; //the possition of y is equal to the temparary possition of y
speed = tempspeed; //the speed of the circle is equal to the temparary speed of the circle
size = tempsize; //the size of circle is equal to the temparary size of the circle
} //end myCircle variable fill
void display(){ //how the ellipse is viewed
stroke(0); //a black stroke
fill(255); //a white fill
ellipse(xpos, ypos, size, size); //the circles possition and size
} //end void display
void move(){ //defines how the circle moves in the square
xpos = xpos+speed; //the speed of the circle
xpos = xpos + (speed * xdir);
ypos = ypos + (speed * ydir);
if (xpos > width || xpos <0){ //if the y possition is greater than the height of the box then...
speed *= -1; //then the x possition equals negative one and reverses direction
//xdir *= -1;
addCircle();
} //end if statement
if (ypos > height || ypos <0){ //if the y possition is greater than the height of the box then...
speed *= -1; //then the x possition equals negative one and reverses direction
//ydir *= -1;
addCircle();
} //end if statement
} //end void move
void getSmall(){ //function to make the circles smaller when they hit a wall
size = size/2; //the size of the circle is equal to half of the circles size
} //end void getSmall
void addCircle(){
c2.move();
}
} //end class