Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The script deletes particles from a Dyverso domain ("DY_Domain01") when velocity is greater than a random value between 7.0 m/s and 9.0 m/s:

 

Code Block
languagepy
# Load Python's random number generator
import random

...



# Get domain "DY_Domain01" and its particles, define a speed range
dyversoDomain = scene.get_DY_Domain("DY_Domain01")
particles     = dyversoDomain.getParticles()
velocityMin   = 7.0
velocityMax   = 9.0

...



# Loop through every particle
for particle in particles:
 
	# Get the particle's velocity
	particleVelocity = particle.getVelocity().module()
 
	# Define a random threshold within the speed range
	randomLimit      = random.uniform(velocityMin, velocityMax)
 
	# Delete the particle if its velocity is greater than or equal to the random threshold
	if (particleVelocity >= randomLimit):
		dyversoDomain.removeParticle(particle.getId())