algorithmic modeling for Rhino
I have a simple loop with some sort of particle movement. In the end I've got only the final position of particles. But how do I see every iteration of that loop? I want to have some kind of animation like in Daniel Piker's kangaroo.
This can be tricky. I don't know exactly how Daniel solves it, but there's two main approaches you can take:
A hybrid approach could be to run your simulation asynchronously in another thread and have it constantly update a field in the scripting component. Parallel to this, expire the scripting component in regular intervals or whenever it can and have it output the value of this field.
I am not sure of all the performance and synchronisation implications of having a thread constantly writing a field and another constantly reading it. There are compiler optimizations that can make the local cache of each core have different values (but gh scripting components have these disabled) and probably other unintended consequences i'm not aware about.
But the following works:
private void RunScript(object x, object y, ref object A)
if (task == null || task.IsCompleted)
task = System.Threading.Tasks.Task.Run(() => Animation());
A = point;
// <Custom additional code>
System.Threading.Tasks.Task task = null;
for(int i = 0;i < 1000;i++)
point = new Point3d(i, 0, 0);
// </Custom additional code>
You could also use a timer component to update, rather the Component.Expiresolution.
If you want to draw every single iteration you can put the Component.ExpireSolution(true) line inside the for loop.