We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello! I´m using your program for my class, and I was wondering how to make an ellipse go to the end of the screen and bounce and then to another end and keep bouncing? Also, I wanted to know how do I make a lot of ellipses bounce at the same time. Thank you! Awesome program!
Answers
What have you tried? Have you looked at any of the examples?
http://studio.SketchPad.cc/sp/pad/view/ro.n3zAlnxKVUP/latest
http://studio.SketchPad.cc/sp/pad/view/ro.9oyKfI9kOIa77/latest
The 10 minute "Processing 3 Debugger" video tutorial is entirely working with a simple bouncing ball sketch. It is a single bounce (not both walls), but a good starting point explanation of a bounce. Skip to 7:00 to see the correct code running after the bug is removed.
There are also bouncing ball sketches on the PVector tutorial page, including "Bouncing Ball with No Vectors".
Basically you have a pair of variables for position (say
x
andy
) and in order for ball to move, you add some value to it each frame -velocityX
andvelocityY
. When your ball position reaches the end of the window, you can multiply according velocity variable by -1 and it would change the direction to the opposite.If you wish there to be more then one ball, you definitely need to check out these topics: https://forum.processing.org/two/discussion/8082/from-several-variables-to-arrays https://forum.processing.org/two/discussion/8081/from-several-arrays-to-classes
This post will give information about rebounding from a border and then the follow up post looks at linear motion,