So i am trying to translate/re-create this script below, which is in Java (p5 /P5.js), to PythonScript in Dynamo
and my attempt so far looks like this:
I just want to know if I am going about this the right way? i feel like im not doing the def init correctly? should it be (eg): self.location = location, and then on another line i describe location?
Also, in the processing/java script, the Particle is a class which is then referenced in main script tab… so can i just write out the class Particle first and then do the main code?
Many thanks, i’m trying to learn and any advice/feedback would help me lots
@el-hakimF please post and format your code (both Java and Python).
Also a bit of background of what the Java code does would help.
You’ll need to have one python script node that stores the particle instances and a second one that mutates them. The benefit of using dynamo is that you can do most of the work, like generating random points and directions, on the Dynamo side:
and end up with very minimal python scripts. This is the first one that generates the particles:
def __init__(self, pos, vel):
self.position = pos
self.velocity = vel
self.position = self.position.Add(self.velocity)
pts, vecs = IN
OUT = map(Particle, pts, vecs)
and the second script that initiates the move:
particles = IN
for p in particles:
OUT = [p.position for p in particles]
This is pretty barebone and doesn’t include the part where the particles are oscillated but should be enough to get you started. You’ll have to figure the rest out on your own.
That’s so helpful - thank you very much! Really appreciate it. Yes, it is the perfect starting point