1

I'm new to p5.js and I'm trying to create a horizontal line by using p5.js with the position 21 clmtrackr.js. But the line is moving. I want to create the line with not moving. Here my code.

var ctracker;
var trigHeight = 0;
var ypos = 0;
var button;
var test = false;

function setup() {
  var videoInput = createCapture();
  videoInput.size(400, 300);
  videoInput.position(0, 0);

  var cnv = createCanvas(400, 300);
  cnv.position(0, 0);

  ctracker = new clm.tracker();
  ctracker.init(pModel);
  ctracker.start(videoInput.elt);

  noStroke();

  button = createButton("set height");
  button.position(150, 260);
  button.mousePressed(showLine)
  background(100);
}

function draw() {
  clear();
  noStroke();

  var positions = ctracker.getCurrentPosition();
  for (var i = 0; i < positions.length; i++) {
    fill(0, 255, 0);
    rect(positions[i][0], positions[i][1], 3, 3);
    if (i == 21) {
      ypos = positions[i][1];
    }
  }
  stroke("rgb(0,255,0)");
  strokeWeight(4);
  test && line(0, trigHeight, width * 2, trigHeight
}

function showLine() {
  test = true;
}

Thank you.

  • 1
    What is `clmtrackr.js`? If all you want to do is show a horizontal line, what do you have all that extra code? What is your end goal? – Kevin Workman Mar 28 '18 at 17:10

0 Answers0