Skip to content

Instantly share code, notes, and snippets.

@s-cork
Last active March 17, 2021 01:51
Show Gist options
  • Save s-cork/3397e26bc62e9d82a339372d1f613299 to your computer and use it in GitHub Desktop.
Save s-cork/3397e26bc62e9d82a339372d1f613299 to your computer and use it in GitHub Desktop.
p5 skulpt
http://g.recordit.co/CWfjWxrBqz.gif
from p5 import p5
p = p5()
c = p.createCanvas(720, 400)
c.parent('turtle')
class Particle:
def __init__(self, position):
self.acc = p.createVector(0, 0.05);
self.vel = p.createVector(p.random(-1, 1), p.random(-1, 0));
self.pos = position.copy()
self.life = 255
def run(self):
self.update()
self.display()
def update(self):
self.vel.add(self.acc)
self.pos.add(self.vel)
self.life -= 2
def display(self):
p.stroke(200, self.life);
p.strokeWeight(2);
p.fill(127, self.life);
p.ellipse(self.pos.x, self.pos.y, 12, 12);
def isDead(self):
return self.life < 0;
class ParticleSystem:
def __init__(self, position):
self.origin = position.copy()
self.particles = []
def addParticle(self):
self.particles.append(Particle(self.origin))
def run(self):
for p in self.particles:
p.run()
if p.isDead():
self.particles.remove(p)
position = p.createVector(p.width//2, 50)
system = ParticleSystem(position)
def draw():
p.background(51)
system.addParticle()
system.run()
while True:
draw()
@s-cork
Copy link
Author

s-cork commented Oct 20, 2020

CWfjWxrBqz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment