Created
July 31, 2015 07:45
-
-
Save iamricard/44067977f5ffab0ad439 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
// A simple Particle class | |
window.Particle = function(position, acceleration) { | |
this.acceleration = createVector(0, acceleration || 0.15); | |
this.velocity = createVector(random(-1, 1), random(-1, 0)); | |
this.position = position.copy(); | |
this.lifespan = 255.0; | |
}; | |
Particle.prototype.run = function() { | |
this.update(); | |
this.display(); | |
}; | |
// Method to update position | |
Particle.prototype.update = function(){ | |
this.velocity.add(this.acceleration); | |
this.position.add(this.velocity); | |
this.lifespan -= 2; | |
}; | |
// Method to display | |
Particle.prototype.display = function() { | |
stroke(200, this.lifespan); | |
strokeWeight(2); | |
fill(127, this.lifespan); | |
ellipse(this.position.x, this.position.y, 12, 12); | |
}; | |
// Is the particle still useful? | |
Particle.prototype.isDead = function(){ | |
if (this.lifespan < 0) { | |
return true; | |
} else { | |
return false; | |
} | |
}; | |
window.ParticleSystem = function() { | |
this.particles = []; | |
}; | |
ParticleSystem.prototype.addParticle = function(acceleration) { | |
var x = random(0, windowWidth) | |
var y = random(0, windowHeight) | |
var position = createVector(x, y) | |
this.particles.push(new Particle(position, acceleration)); | |
}; | |
ParticleSystem.prototype.run = function() { | |
for (var i = this.particles.length-1; i >= 0; i--) { | |
var p = this.particles[i]; | |
p.run(); | |
if (p.isDead()) { | |
this.particles.splice(i, 1); | |
} | |
} | |
}; |
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
//ruby -run -e httpd . -p 5000 | |
//cd ~/desktop/github/play_remix | |
function preload() { | |
bass = { | |
sound: loadSound('/audio/BASS.ogg'), | |
playing: false, | |
play: function() { | |
this.sound.play(); | |
this.playing = true; | |
} | |
}; | |
breaks = { | |
sound: loadSound('/audio/BREAKS.ogg'), | |
playing: false, | |
play: function() { | |
this.sound.play(); | |
this.playing = true; | |
} | |
}; | |
pad = { | |
sound: loadSound('/audio/PAD.ogg'), | |
playing: false, | |
play: function() { | |
this.sound.play(); | |
this.playing = true; | |
} | |
}; | |
} | |
function setup() { | |
createCanvas(windowWidth, windowHeight); | |
padPlay = new p5.AudioIn(); | |
fftPad = new p5.FFT(); | |
fftPad.setInput(pad.sound); | |
padAmplitude = new p5.Amplitude(); | |
padAmplitude.setInput(pad.sound) | |
system = new ParticleSystem(); | |
} | |
function mousePressed(){ | |
bass.play(); | |
breaks.play(); | |
pad.play(); | |
} | |
function draw() { | |
var drawPad = fftPad.analyze(); | |
var backgroundPad = padAmplitude.getLevel(); | |
var showBreaks = breaks.sound.getLevel(); | |
// H, S & B integer values | |
colorMode(HSB); | |
background(255, 105, backgroundPad*255); | |
beginShape(); | |
for (var i = 0; i < drawPad.length; i++) { | |
point(i, drawPad[i]); | |
} | |
endShape(); | |
if (showBreaks > 0.01) { | |
system.addParticle(); | |
} | |
system.run(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment