Moving object from right to left

Hi Guys! I am new here, and new to coding. Below is an example of some first code I wrote and I can't figure out how to get the ellipse bouncing back and forth between the edges of the frame. I added some code for the first ellipse to move back when it hits the right end of the frame (bold section), but so far it doesn't want to move in the opposite direction. Answers are welcome! Thanks in advance!!

float circle1; float circle2; float circle3; float circle4; float circle5; float circle6; void setup () { size(640,360); circle1 = width/2; circle2 = width/2; circle3 = width/2; circle4 = width/2; circle5 = width/2; circle6 = width/2; } void draw() { background(50); fill(220); ellipse(circle1,100,30,30); ellipse(circle2,200,4,4); ellipse(circle3,10,4,4); ellipse(circle4,300,6,6); ellipse(circle5,150,10,10); ellipse(circle6,130,10,10); ** circle1 = circle1+2;** circle2 = circle2-1; circle3 = circle3+0.8; circle4 = circle4-0.5; circle5 = circle5+2; circle6 = circle6-2; ** if(circle1 >= 640) { circle1 = circle1-2; }** }

Answers

Sign In or Register to comment.