Last active
April 28, 2019 17:28
-
-
Save Erendis42/4346e140f028fab431d7a171dd9267d8 to your computer and use it in GitHub Desktop.
This file contains 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
import processing.sound.*; | |
SinOsc sin = new SinOsc(this); | |
float flakeSize; | |
int numberOfFlakes = 500; | |
int maxSize = 10; | |
color bg = #000044; | |
color fg = #FFFFFF; | |
// The statements in the setup() function | |
// execute once when the program begins | |
Flake[] flakes; | |
void setup() { | |
size(1280, 720); // Size must be the first statement | |
stroke(fg); // Set line drawing color to white | |
fill(fg); | |
frameRate(30); | |
flakes = new Flake[numberOfFlakes]; | |
for (int i = 0; i < numberOfFlakes; i = i+1) | |
{ | |
Flake f = new Flake(); | |
flakes[i] = f; | |
} | |
} | |
// The statements in draw() are executed until the | |
// program is stopped. Each statement is executed in | |
// sequence and after the last line is read, the first | |
// line is executed again. | |
void draw() { | |
background(bg); // Clear the screen with the background color | |
for (int i = 0; i < numberOfFlakes; i++) | |
{ | |
Flake f = flakes[i]; | |
if(f.padding != 0 && f.padding < f.amplitude - 2) | |
{ | |
f.x += f.direction * (-(sqrt(f.padding * f.amplitude) + f.amplitude)) / 250; | |
} | |
if(f.padding > f.amplitude) | |
{ | |
f.padding = 0; | |
f.direction *= -1; | |
} | |
else | |
{ | |
f.padding += f.size; | |
} | |
f.y += f.size / 5; | |
if(f.y > height) | |
{ | |
flakeSize = f.size; | |
thread("playSound"); | |
f.initialize(0); | |
} | |
} | |
for (int i = 0; i < numberOfFlakes; i++) | |
{ | |
Flake f = flakes[i]; | |
f.display(); | |
} | |
} | |
void playSound() | |
{ | |
sin.play(100*flakeSize, 0.1); | |
delay(100); | |
sin.stop(); | |
} | |
class Flake | |
{ | |
float x; | |
float y; | |
int direction; | |
float size; | |
int padding; | |
float amplitude; | |
Flake() | |
{ | |
this.initialize(); | |
} | |
void initialize() | |
{ | |
x = random(width); | |
y = int(random(height)); | |
int r = int(random(10)); | |
if(r % 2 == 0) | |
{ | |
direction = -1; | |
} | |
else | |
{ | |
direction = 1; | |
} | |
size = random(maxSize) + 1; | |
amplitude = pow(size, 2.0) + size * 25; | |
padding = int(random(amplitude)); | |
} | |
void initialize(int y) | |
{ | |
initialize(); | |
this.y = y; | |
} | |
void display() | |
{ | |
circle(x,y,size); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
watch this on YouTube: https://youtu.be/5VVEBGs19nQ