美文网首页
ScribblePerson

ScribblePerson

作者: 轻荷 | 来源:发表于2015-10-24 16:20 被阅读17次
    scribble person
    import processing.video.*;
    
    // Two global variables
    float x;
    float y;
    Capture video;
    
    void setup() {
      size(320, 240);
      smooth();
      background(255);
      video=new Capture(this, 320, 240, 15);
      video.start();
    
      // Start x and y in the center
      x = width/2;
      y = height/2;
    }
    void draw() {
      if (video.available()) {
        video.read();
      }
      video.loadPixels();
    
      // Pick a new x and y
      float newx = constrain(x + random(-20, 20), 0, width-1);
      float newy = constrain(y + random(-20, 20), 0, height-1);
    
      // Find the midpoint of the line
      int midx = int((newx + x) / 2);
      int midy = int((newy + y) / 2);
      int loc=(midy+1)*video.width-midx-1;
      color c=video.pixels[loc];
      
      // Draw a line from x,y to the newx,newy
      stroke(c);
      strokeWeight(4);
      line(x, y, newx, newy);
      // Save newx, newy in x,y
      x = newx;
      y = newy;
    }
    

    相关文章

      网友评论

          本文标题:ScribblePerson

          本文链接:https://www.haomeiwen.com/subject/tpothttx.html