Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

How can i combine the first shape in the camera code?(develop the shape with the movement of a cam)

$
0
0

SHAPE CODE:

translate(width/2, height/2); //Specifies an amount to displace objects within the canvas
  beginShape(); //function that begins recording vertices for a shape
  for (int i=0; i<n; i++) {
    float ang = map(i, 0, n, 0,TWO_PI); //the map() is converting the value in i which ranges from 0 to n into a number from 0 to TWO_PI(a mathematical constant)
    float rad = map(noise(i*nfAng, frameCount*nfTime), 0, 1, minRad, maxRad);
   // the radius using noise() to generate a 'random' number between minRad and maxRad so the resulting circle won't be round but will be wiggly.
    float x = rad * cos(ang);// printing on screen
    float y = rad * sin(ang);//printing on screen
    curveVertex(x, y);// Specifies vertex coordinates for curves.


  }
  }
  endShape(CLOSE);// funtion that stops recording verticles for a shape
}

CAMERA CODE:

    import processing.video.*;

    Capture video;
    PImage prevFrame;

    float threshold = 50;
    float totalMotion;
    float avgMotion;

    int a = 0, mw, mh, r = 100;
    float nC = 110;
    boolean addMode = false;

    void setup() {
      size(640, 360);
      background(255);
      noStroke();

      mw = width/2;
      mh = height/2;

      video = new Capture(this, width, height);
      video.start();
      prevFrame = createImage(video.width, video.height, RGB);


    }

    void draw() {
      video.loadPixels();
      prevFrame.loadPixels();

      totalMotion = 0;

      for (int i = 0; i < video.pixels.length; i ++ ) {
        color current = video.pixels[i];
        color previous = prevFrame.pixels[i];
        float r1 = red(current);
        float g1 = green(current);
        float b1 = blue(current);
        float r2 = red(previous);
        float g2 = green(previous);
        float b2 = blue(previous);
        float diff = dist(r1, g1, b1, r2, g2, b2);
        totalMotion += diff;
      }

      avgMotion = totalMotion / video.pixels.length;

      fill(0,50);
      rect(0,0,width,height);
      for (int i = 1; i <= nC; i++){
        fill(0,150+sin(radians(a+(360/nC)*i))*55,200+cos(a+(360/nC)*i)*55);
        ellipse(mw+sin(radians(a+(360/nC)*i))*r,mh+cos(radians(a+(360/nC)*i))*r,10*(r/100),10*(r/100));
      }

      a++;

      if (avgMotion > 35)
      {

        r += 5;
        if (addMode)
        {
          nC += .2;
        }
      } else if (r > 100) {
        r -= 10;
      }


      println(avgMotion);
    }

    void captureEvent(Capture video) {
      prevFrame.copy(video, 0, 0, video.width, video.height, 0, 0, video.width, video.height);
      prevFrame.updatePixels();
      video.read();
    }

Viewing all articles
Browse latest Browse all 2896

Trending Articles