Transforming PVectors into p5.vector (or createVector?)

Hi Folks,

I've been reading through every 'convert Processing into P5' document I can get a hold of, and I still can't figure out how to translate PVector's (processing) into p5.vector syntax.

Beneath is code in Processing (working). Beneath that is my code for p5 (not working) I'm pretty sure it's my Vector syntax that is out of wack. Can someone please provide direction? Saying that, there might be other things wrong, and I'm open to suggestions.

PROCESSING:

PImage img;
ArrayList pts;


void setup() {
  img = loadImage("ASKEW A.jpg");

    size(500, 500, P3D);

  pts = new ArrayList();
  findPoints();
}

void draw () {
  background(255);


for (int i = pts.size()-1; i >= 0; i --){
      PVector pt = (PVector)pts.get(i);

      fill(pt.z);

      noStroke();

      stroke(0, 30);
      for (int j = pts.size()-1; j >= 0; j --){
      if(i>1){  
        PVector pt2 = (PVector)pts.get(j);
        if (pt.dist(pt2) < 20){

          int r = 10;
          float x = r * tan(radians(i*(360.0/ (mouseX * tan(3)) )));
          float y = r * sin(radians(i*(360.0/ (mouseY*  tan(3)) )));

          int r1 = 2;
          float x1 = r1 * tan(radians(i*(360.0 / (mouseX* tan(3)))));
          float y1 = r1 * sin(radians(i*(360.0 / (mouseY* tan(3)))));


          stroke(0, 30);
          line(pt.x + x, pt.y + y, 
          pt2.x + x1, pt2.y + y1);
        }
      }
    }
  }
}

void findPoints(){

  img.loadPixels();
  for (int i = img.width-1; i >= 0; i -= 3){
    for (int j = img.height; j >=0; j -= 3){

      color c = img.get(i, j);
      if (brightness(c) < 255){
        pts.add(new PVector(i, j, brightness(c)));
      }
    }
  }
}

p5 :

var img;
var pts = [];
var i, j;


function setup() {

  createCanvas(500, 500);

    img = loadImage("ASKEW A.jpg");
    findPoints();
    }


function draw () {
  background(255);

for (i = pts.length()-1; i >= 0; i --){
      var pt = new p5.Vector.pts.get(i);
      fill(pt.z);

      noStroke();

      stroke(0, 30);
      for (j = pts.length()-1; j >= 0; j --){
      if(i>1){  
        var pt2 = new p5.Vector.pts.get(j);
        if (pt.dist(pt2) < 20){

          var r = 20;
          var x = r * tan(radians(i*(360.0/ (mouseX) )));
          var y = r * sin(radians(i*(360.0/ (mouseY) )));

          var r1 = 2;
          var x1 = r1 * tan(radians(i*(360.0 / (mouseX))));
          var y1 = r1 * sin(radians(i*(360.0 / (mouseY))));


          stroke(0, 30);
          line(pt.x + x, pt.y, 
          pt2.x + x1, pt2.y + y1);
        }
      }
    }
  }
}


function findPoints(){

  img.loadPixels();
  for (var i = img.width-1; i >= 0; i -= 3){
    for (var j = img.height; j >=0; j -= 3){

      var c = img.get(i, j);
      if (brightness(c) < 255){
        pts.push(new p5.Vector(i, j, brightness(c)));
      }
    }
  }
}

Answers

Sign In or Register to comment.