import processing.video.*; Capture camera; PFont font; int scanTolerance = 10; int scanRange = 4; float[][][] baseScreen; int budyNum = 200; Budy[] budyList; int iTemp, flag, process; float fTemp; int lastFrame, lastMilli, lastFPS, FPS; void setup () { size (320, 240); colorMode (RGB, 255); framerate (30); smooth (); // Ne pas oublier de créer une font font = loadFont("LucidaConsole-12.vlw"); textFont(font, 12); println (Capture.list()); // Ecrire si dessous le nom de sa camera // (renvoié dans la console par la fonction précédente) String s = "Logitech QuickCam Messenger-WDM"; camera = new Capture (this, s, width, height, 30); baseScreen = new float[width][height][4]; process = -1; budyList = new Budy[budyNum]; for (int i=0; i 0 && yn > 0 && xn < width && yn < height){ if (baseScreen[xn][yn][3] > fTemp - scanTolerance && baseScreen[xn][yn][3] < fTemp + scanTolerance){ flag = 0; } } } } if (flag == 1){return true;}else{return false;} } void setBaseScreen () { camera.read (); for (int x=0; x < width; x++){ for (int y=0; y < height; y++){ baseScreen[x][y][0] = red(camera.pixels[y*width+x]); baseScreen[x][y][1] = blue(camera.pixels[y*width+x]); baseScreen[x][y][2] = green(camera.pixels[y*width+x]); baseScreen[x][y][3] = (baseScreen[x][y][0] + baseScreen[x][y][1] + baseScreen[x][y][2]) / 3; } } if (process == -1){process = 0;} println ("Base Screen Set at " + hour() + ":" + minute()); } void showDifferences () { loadPixels (); for (int x=0; x < width; x++){ for (int y=0; y < height; y++){ if (hasChanged (x, y) == true){pixels[iTemp] = color (255,0,0);} } } updatePixels (); } ////////////////////////////// // BUDY Classe ////////////////////////////// class Budy { float X, Y, A; int id, flag; Budy (float x, float y, int n) { id = n; X = x; Y = y; A = random (5,10) / 10; } void draw () { noStroke (); fill (0); ellipse (X,Y, 5,5); } void update () { if (hasChanged (int (X), int (Y)) == false && Y < height - A) { Y += A; }else{ flag = 0; while (flag == 0 && Y > 1+A) { Y -= 1; if (hasChanged (int (X), int (Y)) == false) flag = 1; } } } } ////////////////////////////// // MISC Functions ////////////////////////////// void keyPressed () { if(key == CODED) { if (keyCode == ESC) { // Exit application }else if (keyCode == ALT) { saveFrame("screenshots/video_rain ####.tga"); } }else if (key == 'p'){ setBaseScreen (); }else if (key == 'i'){ if (process == 0){ process = 1; println ("process ON"); } }else if (key == 'o'){ if (process == 1){ process = 0; println ("process OFF"); } }else if (key == 'r'){ scanRange ++; }else if (key == 'f'){ if (scanRange > 1){scanRange --;} }else if (key == 't'){ scanTolerance ++; }else if (key == 'g'){ if (scanTolerance > 1){scanTolerance --;} } } void console () { fill (0, 255, 0); text("scanTolerance = " + scanTolerance, 4, 32); text("scanRange = " + scanRange, 4, 48); // calculate the FPS smooth it and display the result if (millis()-lastMilli != 0 && frameCount != lastFrame){ FPS = floor((frameCount-lastFrame) * (1000 / (millis()-lastMilli))); FPS = floor((FPS + (lastFPS*9)) / 10); text(FPS + " FPS", 4, 96); lastFrame = frameCount; lastMilli = millis(); lastFPS = FPS; }else{ text(FPS + " FPS", 4, 96); } }