Last active
March 17, 2021 01:51
-
-
Save s-cork/3397e26bc62e9d82a339372d1f613299 to your computer and use it in GitHub Desktop.
p5 skulpt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://g.recordit.co/CWfjWxrBqz.gif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Author
s-cork
commented
Oct 20, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment