Skip to content

Instantly share code, notes, and snippets.

@bilalsavas
Last active August 29, 2015 14:02
Show Gist options
  • Save bilalsavas/12c3c70a6ab33811bd7a to your computer and use it in GitHub Desktop.
Save bilalsavas/12c3c70a6ab33811bd7a to your computer and use it in GitHub Desktop.
import processing.video.*;
Capture video;
int fWidth=640;
int fHeight=360;
boolean[][] prevFrame = new boolean[fWidth][fHeight];
void setup()
{
frameRate(10);
size(fWidth, fHeight);
splatpoop = new ArrayList();
testLayer = createGraphics(width, height);
String[] cameras = Capture.list();
if (cameras.length == 0) {
println("There are no cameras available for capture.");
exit();
}
else {
println("Available cameras:");
for (int i = 0; i < cameras.length; i++) {
println(cameras[i]);
}
video = new Capture(this, cameras[3]);
video.start();
}
for (int x=0;x<width;x++)
{
for (int y=0;y<height;y++)
{
prevFrame[x][y]=false;
}
}
}
boolean currentPixel;
void draw()
{
if (video.available() == true) {
video.read();
}
set(0, 0, video);
filter(THRESHOLD);
for (int x=0;x<width;x++)
{
for (int y=0;y<height;y++)
{
currentPixel=(get(x, y)==color(#000000)) ? true : false;
if (prevFrame[x][y]!=currentPixel)
{
set(x, y, color(255, 0, 0));
}
prevFrame[x][y]=currentPixel;
}
}
for (int x=0;x<=width+80;x+=40)
{
for (int y=0;y<height;y+=40)
{
if ((get(x+20, y+20)==color(255, 0, 0)) ? true : false)
{
color splc = video.get(x+20, y+20);
for (float i=2; i<20; i+=.20) {
Splash sp = new Splash(x+20, y+20, i, splc);
splatpoop.add(sp);
}
}
}
}
fill(255);
rect(0,0,width,height);
updateSplash();
}
ArrayList splatpoop;
PGraphics testLayer;
class Splash {
int x, y;
float rad, ellipseangle, i;
color c;
Splash(int _x, int _y, float _i, color splc) {
x = _x;
y = _y;
i = _i;
rad = random(2, 10);
ellipseangle = random(0, TWO_PI);
c = splc;
}
void display() {
testLayer.fill(c);
testLayer.noStroke();
float spotX = x + cos(ellipseangle)*2*i;
float spotY = y + sin(ellipseangle)*3*i;
testLayer.ellipse(spotX, spotY, rad-i, rad-i+random(1, 2));
}
void update() {
y = y+1;
}
}
void updateSplash() {
testLayer.beginDraw();
if (splatpoop.size() > 600)
{
for (int i=0;i<splatpoop.size()-400;i++)
{
splatpoop.remove(i);
}
}
for (int i=0; i<splatpoop.size(); i++) {
Splash s = (Splash) splatpoop.get(i);
s.display();
if(random(80)<40)
s.update();
if (s.y>height)
splatpoop.remove(i);
}
testLayer.endDraw();
image(testLayer,0,0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment