Study Bubble Animation : Speed of Movement & Rate of Generation

Introduction
This example is made to help intermediate users who wish to do animation (movement) of objects eg. points (can easily apply to other objects where points are used to determine positions), and also control the rate of generation(and appearance) of instances of the objects, understand some of the difficult concepts and tricks better.[br][br](Note : Refer to[url=https://www.geogebra.org/m/Chsu6yEg] https://www.geogebra.org/m/Chsu6yEg[/url] on simulating the generation of instances of bubbles appearing using poisson process, 16 Nov 2017)[br][br]Try the animation below. Download a copy and access the Geogebra scripts within the objects to understand the commands and parameters used. [br]There is insufficient space to explain every detail here so do refer to the [url=https://wiki.geogebra.org//en/Manual]Geogebra Manual[/url] and search for the [url=https://wiki.geogebra.org/en/Objects]Geogebra objects[/url], [url=https://wiki.geogebra.org/en/Category:Commands]commands list[/url], and [url=https://wiki.geogebra.org/en/Tutorial:Introduction_to_GeoGebraScript]scripting tutorial and references[/url]
Primer on Geogebra animations (Updated on 13 Nov)
In Geogebra animation, when using the number or angle object (with slider) to animate, a crucial point to note is that the "animation speed" is a rate per cycle and not per unit time. [br][br]When animation speed is set to 1, the duration to complete one cycle (animating from minimum value to maximum value, with some increment) is approximately 13 seconds on a laptop with Intel Core I7 CPU. (There may be variation in this real time duration for different PC/laptops)[br]Note that this duration is independent of the minimum, maximum or increment (unless set to zero or logically not required to increment, eg max = min ).[br]For example if object r's minimum is 0 and maximum is 15, changing increment from 0.1 up to 15 will not change the time taken form r to change from 0 to 15, which is constant 13 seconds for the same laptop. [br]If the minimum is set to 10 and maximum set to 100, irregardless of the increment, the real time taken for r to increase from 10 to 100 is still 13 seconds. [br][br]To summarize the crucial point from above, animation speed is a rate per cycle.[br]The standard speed of 1 means it takes approximately 13 seconds to animate from mini to max value once.[br]The duration of a cycle (from min to max value), which I denote here as T, is inversely proportional to the animation speed (denoted as S).[br]Hence in the standard case when S =1 , T = 13 also means that T = 13/S.[br]So when speed S = 2, the time taken would be 13/2 = 6.5 seconds.[br][br]A side point to note is that an animated object may require to be at constant speed or variable speed.[br]S can be made dynamic using algebraic expressions instead of numerical constants.[br][br]The next thing to note is the generation of the instances of bubbles. The rate at which bubbles are generated and appear on screen are actually controlled via separate animation. With reference to the example, the rate at which the bubbles are required to appear (r_b) can be adjusted through a number slider, which then feeds into the animation speed of another number slider. The second number slider (r) , when animated, counts whole numbers, at a rate equivalent to the required real time.[br][br](updated 13 Nov - The value for duration to complete one cycle (from min to max value), T was adjusted to 13s instead of 14s previously indicated, para 1, 2, 3 revised)
How do you do this ?
[u]Notes on Bubble Animation along path : “Speed of travel” & “Rate of Generation”[/u][br][br]1. Animation speed (GGB) : [br] Value of 1 is approximately 13 seconds to complete 1 cycle.[br] The speed here refers to how fast one cycle is. [br] And it is proportional to the time taken[br] When value is 2, it takes about 6.5 seconds per cycle.[br] When value is 4, time taken is 3.25 seconds per cycle[br][br]2. Note the min and max or increment does not affect the cycle speed but [br] if the position of object depends on min and max then the difference betw min and max[br] if great, implies that the object travels faster if the cycle speed is increased.[br][br]3. In this simulation, r_b is used to input the number of bubbles to be generated per minute[br] r is set to count numbers automatically when animated, at a cycle speed of 13*r_b / 900[br] How is the speed of r obtained ?[br] [br] If there are r counts per cycle and each cycle is 13 seconds for simulation speed S = 1,[br] Real time per cycle = 13/S[br] If each cycle has r counts, then each count = 13/S)/r seconds.[br] So there will be 60/((13/S)/r) counts per minute.[br] [br] We want to simulate r_b counts per minute real time[br] [br] Hence r_b = 60/((13/S)/r) -------------- Eqn (1)[br] [br] Expressing required simulation speed S in terms of r_b counts per minute, [br] and with r count per cycle = 15, from Eqn (1): [br][br] (13/S)/15 = 60/r_b[br][br] 13/S = 60*15/r_b[br][br] S = 13*r_b/900[br][br] (Updated 13 Nov to change duration of T to be 13 seconds when S = 1)
4. r is used as a counter to release bubbles U1 and U2. The bubbles to be [br] generated per minute, r_b, affects the counting speed of r (S = 13*r_b/900)[br] and hence the release of the bubbles.[br][br]5. n_1 and n_2 are path parameters for U1 & U2 respectively, which are defined as [br] points on segment f, using U1 = Point[f], U2 = Point[f]. Path parameters n_1 and n_2 [br] each have been set to animate with constant speed of 2 (abt 7 seconds real time)[br] Bubbles rise up at a constant speed. As n_1 & n_2 updates, the script commands [br] U1 = Point[f,n_1], U2 = Point[f,n_2] will move U1, U2 along the path of segment f. [br] Change this animation speed if you require a different visual impact of the speed of object [br] Animations are set as “Increasing once” ie. U1 and U2 will stop at end point, and [br] wait to be triggered to move again from start point, once r is updated by increment of 1[br] If r is odd - U1 restarts, if r is even U2 restarts. Checking r odd or even is achieved using : [br] Mod(r,2) when r is odd returns the value 1, and gives 0 when r is even[br] [br] The script below for animation is found in the OnUpdate section in object r.[br] SetValue[n_1,If[Mod[r,2]>0,If[anim,If[n_1>0&&n_1<0.99,n_1,0],n_1],n_1]][br] StartAnimation[n_1,true][br] SetValue[n_2,If[Mod[r,2]<1,If[anim,0,n_2],n_2]][br] StartAnimation[n_2,true][br] For Increasing Once animations, even when StartAnimation is set true, [br] if the value is already at maximum, then animation ends there and does not restart.[br] The values need to be reset to less than the maximum value for the animation to start.[br]
6. Button button1 is used to start animation of bubbles via animation of counter r.[br] The script in button1 On Click is :[br] SetValue[anim,!anim][br] SetCaption[button1,If[anim,“Stop Bubbles' Animation”,“Animate Bubbles U1 & U2”]][br] StartAnimation[r,anim][br] SetValue[r,If[anim,1,r]][br] StartAnimation[n_1,anim][br] StartAnimation[n_2,anim]

Information: Study Bubble Animation : Speed of Movement & Rate of Generation