We are about to switch to a new forum software. Until then we have removed the registration on this forum.
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
Code doesn't inline nicely, ill post an image instead
Edit post (gear in the top right corner), select code, hit ctrl+o
This code says if the variable "x" is larger than the value of the width of the window or below 0, then multiply the variable xDir by -1. Now if you use "x" as the first parameter for ellipse() and then you multiply it with "xDir" every frame.
For more on how to edit your post so that people can read the code and help you, see:
https://forum.processing.org/two/discussion/15473/readme-how-to-format-code-and-text
Thanks guys for the help!