-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path12_ParticleSystem.py
More file actions
57 lines (50 loc) · 1.64 KB
/
12_ParticleSystem.py
File metadata and controls
57 lines (50 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#Information about our Script
import rhinoscriptsyntax as rs
import math
import random
class Particle:
#Constructor
def __init__(self, _startPoint):
self.location = _startPoint
self.x = random.uniform(-2,2)
self.y = random.uniform(-2,2)
self.z = random.uniform(10,20)
self.velocity = rs.VectorCreate([self.x,self.y,self.z],[0,0,0])
self.acceleration = rs.VectorCreate([0,0,0],[0,0,0])
def run(self):
self.update()
self.display()
def update(self):
self.velocity = rs.VectorAdd(self.velocity, self.acceleration)
self.location = rs.VectorAdd(self.location, self.velocity)
def display(self):
rs.AddSphere(self.location,5)
def applyForce(self, _force):
self.acceleration = rs.VectorAdd(self.acceleration, _force)
class ParticleSystem:
def __init__(self, _location):
self.particles = []
self.origin = rs.VectorCreate(_location,[0,0,0])
def addParticle(self):
self.particles.append(Particle(self.origin))
def applyForce(self, _force):
for p in self.particles:
p.applyForce(_force)
def run(self):
for p in self.particles:
p.run()
gravity = rs.VectorCreate([0,0,-0.5],[0,0,0])
wind = rs.VectorCreate([0.5,1.0,0.0],[0,0,0])
origin1 = rs.GetPoint("Please specify origin 1")
origin2 = rs.GetPoint("Please specify origin 2")
ps1 = ParticleSystem(origin1)
ps2 = ParticleSystem(origin2)
for i in range(100):
ps1.applyForce(wind)
ps1.applyForce(gravity)
ps2.applyForce(wind)
ps2.applyForce(gravity)
ps1.addParticle()
ps2.addParticle()
ps1.run()
ps2.run()