We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Been tasked with a small job of creating a circle that grows in size to a certain size, and then shrinks back into a dot.
Along with this, another object in the program, upon touching the circle, will make the circle disappear and reappear in another random area of the screen, and the circle would still be looping its shrinking and growing. Each time the circle disappears, a tally keeps track of how many times it happens.
At first I thought loops would help design the circle, but I can only get the circle to grow to the required size, but not shrink back down to diameter 1. Can anyone help me?
Answers
Addendum: I have the other object in the program animating just fine, but I have no idea how to make the object and the circle interact with each other.
I am not looking for code by the way, but I would like directions to understanding the logic of how to design the code. I feel like loops are the right answer, but so far I only know how to make the circle grow, or shrink, but not continuously loop between growing and shrinking.
Have a look here for the "pulsing" effect.
You describe a triangular wave, but maybe another kind of wave can be used also.
http://forum.processing.org/two/discussion/7147/some-simple-pulse-equations-using-trig#latest
or a cleaner triangle wave:
http://forum.processing.org/two/discussion/comment/40035/#Comment_40035
For the others questions code would be great for getting help. Generally speaking:
It looks like a job for classes (OOP).
The interaction seems to be a collision detection between the two objects.
http://forum.processing.org/two/discussion/8291/rollover-for-animation
You have a few requirements, maybe work on just the growing / shrinking before tackling the other ones
If you are drawing an ellipse() (lets say its position is fixed) where its size is controlled with a variable like this:
ellipse(100, 200, unitSize, unitSize);
then it sounds like you understand that making unitSize's value larger will make the ellipse() grow. The problem is that in order to know whether or not you should make unitSize's value larger or smaller requires state information. Add a boolean variable which represents the state, I'm going to call that shouldGrow
When the sketch starts shouldGrow should be true. Every frame check if shouldGrow is true or false. If it is true then make unitSize's value larger and if it is false then make unitSize's value smaller. When unitSize's value is large enough then make shouldGrow false. When shrinking is occurring (because shouldGrow is false) and unitSize's value becomes small enough make shoudGrow true
Post some code when you have that working (or an attempt if it is confusing) and then it will be easier for people to guide you through the other requirements
yeah, or when you add something to the size make that what you add (the Addendum as you said) be once positve and once negative
also the pos of the ellipse are two vars that get changed
upon touching the circle
How about this? I want to make it grow fast and then shrink slowly back and then repeat. here is my code.
@zumba29
Format your code. Edit your post, select your code and hit ctrl+o.
Kf
@zumba29
Have a look at this reference and then check the sample code below. I hope this helps,
Kf
http://p5js.org/reference/#/p5/createGraphics
Three things:
A) he specifically wasn't asking for code, just hints
B) he probably didn't want JavaScript
C) he probably solved the problem himself in the 18 months between him asking the question and you answering
@koogs I was answering zumba29's question. I only focus in recent posts BTW. No clue where you are coming from.
Kf