@name floppy
@inputs 
@outputs 
@persist T H K X0 X V0 V C X02 X2 V02 V2 
@trigger 
interval(1000/17)
H = 1/17
T++
if (first()) {
    function angle vectorToCylinder(V:vector) {
        # gets the angles from a direction vector and outputs the rotation angle 
        # required to aling a holo cylinder with that vector
        CAng = ang(0, 90, 90)
        VAng = V:toAngle()
        RAng = (matrix(CAng) * matrix(ang(VAng:yaw(), 0, VAng:pitch()))):toAngle()
        return RAng
    }
#you can also initiate movement by setting these to 20 or so...
    X = 0
    V = 0
    X2 = 0
    V2 = 0
    K = 5
    C = 0
    for (K = 2, 12) {
        holoCreate(K)
        holoColor(K, vec(220, 180, 180))
    }
    for (K = 2, 9) {
        holoModel(K, "cylinder")
        holoScaleUnits(K, vec(20, 20, 11))
        holoColor(K, vec(210, 180, 180))
    }
    holoModel(10, "icosphere3")
    holoScaleUnits(10, vec(22, 22, 22))
    holoColor(10, vec(230, 180, 220))
    
    holoModel(11, "icosphere3")
    holoScaleUnits(11, vec(45, 45, 45))
    
    holoModel(12, "icosphere3")
    holoScaleUnits(12, vec(45, 45, 45))
    
    for (K = 2, 10) {
        holoPos(K, entity():pos() + K * 10 * entity():up())
    }
}
V0 = V
X0 = X
A = -K * X - V * C 
V = V0 + A * H
X = X0 + V * H + entity():velL():y() / 100
X *= 0.95

V02 = V2
X02 = X2
A2 = -K * X2 - V2 * C 
V2 = V02 + A2 * H
X2 = X02 + V2 * H - entity():velL():x() / 100
X2 *= 0.95
#holoPos(1, entity():pos() + vec(0, 0, 40 + X))
for (K = 2, 10) {
    S = 0.000001 
    Length = (K * 10)
    Deflection = 2 * S * X * Length^3
    Angle = toDeg(3 * S * X * (Length + K * 4)^2)
    Deflection2 = 2 * S * X2 * Length^3
    Angle2 = toDeg(3 * S * X2 * (Length + K * 4)^2)
    Ang = (matrix(ang(Angle, 0, 0)) * matrix(ang(0, Angle2, 0))):toAngle()
    Vec2 = entity():up():rotate(Ang)
    holoPos(K, entity():pos() + K * 10 * entity():up() + entity():right() * Deflection + entity():forward() * Deflection2)
    holoAng(K, vectorToCylinder(Vec2))
}
holoPos(11, entity():pos() + 10 * entity():up() + entity():right() * 20 + entity():forward() * 10)
holoPos(12, entity():pos() + 10 * entity():up() + entity():right() * 20 + entity():forward() * -10)
