warning: risk of epilepsy — musique: tno/factory

Du n’importe quoi avec Processing. La seule particularité: chaque image du rendu vidéo n’est composée que de carrés de tailles identiques, dont la rotation dépend de la luminosité du pixel correspondant sur l’image source (webcam). La forme nous apparaît donc grâce à la rotation particulière de chaque carré. Il y a aussi une sorte de délai (volontaire) dans le traitement des images. Comme quoi, le cerveau et la vision, c’est quand même pas mal balèze.

Un autre exemple, appliqué à un dessin (papier) que j’avais fait hier:

OhMyOwl

O RLY?

3 comments

  1. niko mars 1st, 2012 1:29 Reply
    #1

    Le code (pas au format, je sais pas comment faire ici):

    /**
    * Niko 2012-2-29 for http://jaipasfini.org – Thing-a-day-2012
    * this code started from the ASCII Video code by Ben Fry.
    */

    import processing.video.*;
    import processing.opengl.*;

    MovieMaker mm;

    Capture video;
    boolean cheatScreen;

    boolean captureVideo = false;

    float[] bright;
    char[] chars;

    float pixelSize = 1.5; // 1.5
    int rectSize=1; // 1

    float smoothLevel = 1.0;

    public void setup() {
    // size(640, 480, P2D);
    size(1024, 768, P2D);

    video = new Capture(this, 160, 120, 15);
    int count = video.width * video.height;

    // current brightness for each point (used later to smooth display)
    bright = new float[count];
    for (int i = 0; i < count; i++) {
    // set each brightness at the midpoint to start
    bright[i] = 0;
    }

    rectMode(CENTER);

    mm = new MovieMaker(this, width, height, "squarevideo.mov");

    }

    public void captureEvent(Capture c) {
    c.read();
    }

    void draw() {
    background(0);

    frameRate(10);

    pushMatrix();

    float hgap = width / float(video.width);
    float vgap = height / float(video.height);

    scale(max(hgap, vgap) * pixelSize);

    int index = 0;

    for (int y = 1; y < video.height; y++) {

    for (int x = 0; x < video.width; x++) {

    int pixelColor = video.pixels[index];

    int r = (pixelColor >> 16) & 0xff;
    int g = (pixelColor >> 8) & 0xff;
    int b = pixelColor & 0xff;

    //int pixelBright = max(r, g, b); // method 1 : brightness by max
    //int pixelBright = r/3 + g/3 + b/3; // method 1 : brightness by average
    int pixelBright = (int)(0.3*(float)r + 0.59*(float)g + 0.11*(float)b); // luminance

    // stabilize image with smooth pixel value update (implies small delay)
    bright[index] += (float)( pixelBright – bright[index] ) * smoothLevel;

    int pixelValue = (int)bright[index];//pixelBright;

    //pixelColor = pixelBright;
    pixelColor = 220 + (int)(Math.random()*10.0) ; // a bit of noise never hurts

    pushMatrix();

    // Move over for next character
    translate(( video.width – x*1.0 ) / pixelSize, y * 1.0 / pixelSize); // image is like a mirror
    // translate(1.0 / pixelSize, y * 1.0 / pixelSize);

    rotate(((float)pixelValue)/255.0*3.0); // tested from 2.0 to 45.0

    fill(pixelColor);
    rect(0,0,rectSize,rectSize);

    popMatrix();

    index++; // move to next webcam pix
    }
    }

    popMatrix();

    if ( captureVideo )
    mm.addFrame();

    if (cheatScreen)
    image(video, 0, height – video.height);
    }

    public void keyPressed() {
    switch (key) {
    case ‘g’: saveFrame(); break;
    case ‘c’: cheatScreen = !cheatScreen; break;
    case ‘v’: captureVideo = !captureVideo; break;
    case ‘d’: if ( smoothLevel == 1.0 ) smoothLevel = 0.1; else smoothLevel = 1.0; break;
    }
    }

    void stop() { mm.finish(); print( »\n### Stop recording movie ###\n »); super.stop();}

  2. taras mars 1st, 2012 3:30 Reply
    #2

    Super cool! Je pense que je commence utiliser le Processing, ta code est très simple.

  3. virgi mars 1st, 2012 11:53 Reply
    #3

    Merci pour le code, je le garde au cas où je me serve un jour de Processing. L’effet est extra.

Leave a comment

You must be logged in to post a comment.