Rainbow pendulums waves

This model was inspired by Daniel Shiffman's coding Challenge #159:[br][br]https://www.youtube.com/watch?v=NBWMtlbbOag[br][br]The simulation is pretty close to a real one:[br][br]https://www.youtube.com/watch?v=yVkdfJ9PkRQ[br][br]I found the equation used to calculate the length of each pendulum here:[br][br]https://www.education.com/science-fair/article/pendulum-waves/
Script
L = Slider(1, 15, 0.01, 1, 150, false, true, false, false)[br]SetValue(L, 15)[br]#posY = 430[br]#SetCoords(L, 50, posY)[br]SetVisibleInView(L, 1, false)[br][br]O = (0, 0, 0)[br]SetVisibleInView(O, 1, false)[br][br]speed = 1[br]t = Slider(0, 1, 0.01, speed, 150, false, true, false, false)[br]SetVisibleInView(t, 1, false)[br][br]g = Slider(0, 15, 0.01, 1, 150, false, true, false, false)[br]#SetCoords(g, 300, posY)[br]SetValue(g, 9.81)[br]SetVisibleInView(g, 1, false)[br][br]damping = 0.997[br][br]#----------------------------[br]# Auxiliary names[br]#----------------------------[br]Ln = 1...16[br]Llength = Zip(9.81*(120/(2*pi*(13.44+k+1)))^2, k, Ln)[br]LnamAng = Zip("angle"+Text(k), k, Ln)[br]LnamAngV = Zip("angleV"+Text(k), k, Ln)[br]LnamAngA = Zip("angleA"+Text(k), k, Ln)[br][br]SetVisibleInView(LnamAng, 1, false)[br]SetVisibleInView(LnamAngV, 1, false)[br]SetVisibleInView(LnamAngA, 1, false)[br][br]SetVisibleInView(LnamAng, -1, false)[br]SetVisibleInView(LnamAngV, -1, false)[br]SetVisibleInView(LnamAngA, -1, false)[br][br]#----------------------------[br]# Distance between pendulums[br]#----------------------------[br]Ldiff = Sequence(k, k, 0, 0.15, 0.01)[br]size = Length(Ldiff)[br][br]#----------------------------[br]# Lengths of strings[br]# Define angular velocity[br]# Define angular acceleration[br]#----------------------------[br]Execute(Zip("L"+k+" = "+len+"", k, Ln, len, Llength))[br]Execute(Zip(name + " = pi * 0.2 + 0.0 * "+k+"", name, LnamAng, k, Ldiff))[br]Execute(Zip(name + " = 0", name, LnamAngV))[br]Execute(Zip(name + " = 0", name, LnamAngA))[br][br]#----------------------------[br]# Adjust angle by user[br]#----------------------------[br]userAngle = Slider(0, 3.14, 0.01, 1, 150, false, true, false, false)[br]SetValue(userAngle, pi * 0.5)[br]SetCaption(userAngle, "θ")[br]SetLabelMode(userAngle, 9)[br]#SetCoords(userAngle, 50, posY)[br][br]#----------------------------------[br]# Define the force for each pendulum[br]#----------------------------------[br]Execute(Zip("force"+k+" = -g * sin(angle"+k+")", k, Ln))[br][br][br]#----------------------------[br]# Plot each pendulum in 3D[br]#----------------------------[br][br]Lv = Zip(Vector((0,0,0), (0,k,0)), k, Ln)[br]TO = Zip(Translate(O, v), v, Lv)[br][br]SetVisibleInView(Lv, 1, false)[br]SetVisibleInView(TO, 1, false)[br][br]SetVisibleInView(Lv, -1, false)[br]SetVisibleInView(TO, -1, false)[br][br]Execute(Zip("P"+k+" = Translate( Rotate( ( L"+k+" * sin( angle"+k+" ), -L"+k+" * cos( angle"+k+" ) ) , pi/2 , xAxis), "+v+") ", k, Ln, v, Lv))[br]Execute(Zip("SetVisibleInView(P"+k+", -1, false)", k, Ln))[br][br]#Strings[br]Execute(Zip("segment"+k+" = Segment("+origin+", P"+k+")", k, Ln, origin, TO))[br][br]#Pendulums[br]Execute(Zip("S"+k+" = Sphere(P"+k+", 0.5)", k, Ln))[br][br]Execute(Zip("SetDynamicColor(S"+k+", "+k+"/16, 1, 1, 1)", k, Ln))[br][br]#---------------------------------------[br]# Set value of angle A in [br]# relation to the length of string[br]#---------------------------------------[br]Execute(Zip("SetValue(angleA"+k+", (force"+k+")/"+len+") ", k, Ln, len, Llength))[br][br]#----------------------------------------------[br]# Define two booleans for interaction[br]#----------------------------------------------[br]a = false[br]SetCaption(a, "Play")[br]SetVisibleInView(a, 1, true)[br][br]b = false[br]SetCaption(b, "Spin")[br]SetVisibleInView(b, 1, true)[br][br]#--------------------------------------[br]# Frame [br]# (this can be edited manually)[br]#--------------------------------------[br]Q0 = (0,18, 0)[br]Q0' = (-3, 18, 0)[br]Q0'' = (3, 18, 0)[br]Q1 = (0, -1, 0) [br]Q1' = (-3, -1, 0)[br]Q1'' = (3, -1, 0)[br][br]Q3 = (-7, -1, -17)[br]Q4 = (7, -1, -17)[br]Q5 = (-7, 18, -17)[br]Q6 = (7, 18, -17)[br][br]top = Segment( Q0, Q1 )[br]top' = Segment( Q0', Q0'' )[br]top'' = Segment( Q1', Q1'' )[br]leg1 = Segment(Q1', Q3)[br]leg2 = Segment(Q1'', Q4)[br]leg3 = Segment(Q0', Q5)[br]leg4 = Segment(Q0'', Q6)[br]pl : z = -17.6[br][br]SetActiveView(-1)[br]CenterView( (0, 10, -10) )[br]ZoomOut(3)[br][br]#------------------------------------------------------[br]# Add these lines to slider 't' on update[br]#------------------------------------------------------[br][br]#Execute(Zip("SetValue(angleA"+k+", (force"+k+")/"+len+") ", k, Ln, len, Llength))[br]#Execute(Zip("SetValue(angleV"+k+", angleV"+k+" + angleA"+k+"/3)", k, Ln))[br]#Execute(Zip("SetValue(angleV"+k+", angleV"+k+" * damping)", k, Ln))[br]#Execute(Zip("SetValue(angle"+k+", angle"+k+" + angleV"+k+"/3)", k, Ln))[br][br]#------------------------------------------------------[br]# Add this line in boolean 'a' on update[br]#------------------------------------------------------[br][br]#StartAnimation(t, true)[br][br]#------------------------------------------------------[br]# Add this line in boolean 'b' on update[br]#------------------------------------------------------[br][br]#If(b==true, SetSpinSpeed(1), SetSpinSpeed(0))

Information: Rainbow pendulums waves