Hello everyone, I am trying to make an algorithm that allows to simulate the rotating movement of a coin.
The origin point to draw the coin must coincide with the center of the canvas (I must use the variables of the
width and height system to calculate the center).
I clarify that the currency remains fixed in its initial position.
The rotary motion of the coin is around the y-axis.
The color of the coin varies with each movement simulation.
I must declare and initialize the necessary variables so that the algorithm is expressed based on those variables.
I must make use of ellipse(), fill(), random(), background() primitives.
Now, I don’t know how I should use random() and make the coin change color with each movement, can you help me please? thanks in advance!
To rotate about the Y axis you simply use a variable for the third parameter - the width of the eclipse like this
ellipse (100, 100, w, 100);
and then gradually change w from 100 to 0 followed by 0 to 100 then repeat forever.
Use a variable dw for the change in width for each frame. You would need to change the sign of dw depending on whether the coin is getting smaller or bigger.
That should be enough to get you started on your homework. Try it and post your result here.
And to make it look correct, the width w should be abs( 100*cos(angle) ) where angle is a function of time, so something like angle = TAU * frameCount / 120.0; which at 60 fps would take 2 seconds to make a complete turn around. You can then use the value of w to vary the fill color of the coin as well.
For the best effect, the fill should probably be lightest in color when the ellipse is widest, and darkest in color when the ellipse is narrowest. Using the same variables and calculations as above, the fill could then be: