I’m trying to learn python for a bit to improve my Dynamo skills.
I’ve (finally) managed to get a while loop working:
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
s=0
v=0
a=IN[0]
r=IN[1]
t=0
tmax=IN[2]
while t<tmax:
t=t+1
v=(v+a)-(v*v)/a*r
s=s+v
OUT = [v,s]
If it wasn’t clear already I’m trying to simulate movement with air resistance (not with a “real” formula but this ones doesn’t break). Where s is the distance, v the speed, a the acceleration, r, uhm, an “air resistance variable”, t time, and tmax the maximum time.
I’m currently getting the the time and distance from the output and this works well.
But what I’d like to get is arrays that would show the speed and distance at each point in time, but I don’t really understand yet how to deal with arrays yet in this context, it certainly doesn’t seem to work like it does in the Dynamo code.
Thanks in advance!
Remember I’m just doing this as practice so it’s fine if it doesn’t really work in the end, but I’d like to get som understanding on how to work with arrays.