Created
December 29, 2021 15:17
-
-
Save CodeMaster7000/823e28207b22613d8dd62e4345f77dfe to your computer and use it in GitHub Desktop.
A New Year fireworks sprinkler in Python 3.
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 random import randint | |
| from processing import * | |
| numberOfParticules = 40; | |
| position=[] | |
| velocity=[] | |
| lifespan=[] | |
| color=1 | |
| def setup(): | |
| size(300,300) | |
| frameRate(24) | |
| background(0) | |
| stroke(255) | |
| strokeWeight(2) | |
| global numberOfParticules | |
| global position | |
| global velocity | |
| global lifespan | |
| for i in range(0, numberOfParticules): | |
| position.append([0,0]) | |
| if (i < numberOfParticules/2): | |
| velocity.append([randint(-2,2), randint(-10,-5)]) | |
| lifespan.append(randint(20,40)) | |
| else: | |
| velocity.append([0,0]) | |
| lifespan.append(randint(0,40)) | |
| def draw(): | |
| global color | |
| global numberOfParticules | |
| global position | |
| global velocity | |
| global lifespan | |
| background(0) | |
| for i in range(0, numberOfParticules): | |
| color=i%5 | |
| if color==0: | |
| stroke(255,255,255) | |
| elif color==1: | |
| stroke(255,255,0) | |
| elif color==2: | |
| stroke(255,0,255) | |
| elif color==3: | |
| stroke(0,255,0) | |
| elif color==4: | |
| stroke(0,255,255) | |
| point(position[i][0] + 150, position[i][1] + 300 ) | |
| position[i][0]+=velocity[i][0] | |
| position[i][1]+=velocity[i][1] | |
| velocity[i][1]+=0.2 | |
| point(position[i][0] + 150, position[i][1] + 300 ) | |
| lifespan[i]-=1 | |
| if (lifespan[i] < 0): | |
| velocity[i] = [randint(-2,2), randint(-10,-5)] | |
| position[i] = [0,0] | |
| lifespan[i] = randint(0,40) | |
| run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment