How to put the first code in the second code?

edited October 2017 in Library Questions
    int n = 256;
    int minRad = 50; //minimum radius
    int maxRad = 600;//maximum radius
    float nfAng = 0.01; // angle
    float nfTime = 0.005;//at every 0.005 the shape is being developed
    int outnum;



    void setup() {
       fullScreen();

      pixelDensity(displayDensity());
      background (255);// bg color
      noFill();
      stroke(0, 15);
    }

    void draw() {

        background(255);
         } else {
        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
    }

SECOND 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();
}

Answers

  • they are the same.

    please elaborate

  • Okay, looks like you have updated the second code.

    However, your first code is broken. You have an extra } else { line and an extra bracket } -- at least, I'm guessing that is the problem.

    Re:

    How to put the first code in the second code?

    Please describe exactly what you are trying to do.

    You have a "wobbly outline" sketch, and a "video" sketch.

    Are you trying to mask the video inside the wobbly outline?

  • i would like to compine the shape code in the camera code.The camera code include a rect and ellipse. i would like to replace the shape code with these shapes, and the camera captures the motion and the shape will develop.

Sign In or Register to comment.