Hi, I’ve been reading about The Salesman Problem and I’ve seen TSP art, which I’m interested in creating.
I found an existing sketch in gihub and I’m trying to adapt it to randomly read pixels from a black and white image and if the pixel is black it would add it to the “cities” array.
I’m getting the following error: “Cannot make a static reference to the non-static method add(PVector) from the type PVector”
Is there any other way to add an x/y value to a PVector?
Thanks in advance.
PVector[] cities;
int no_of_cities=100;
PImage img;
int xc, yc;
color c;
float recorddistance;
PVector[] bestever;
void setup()
{
size(1024,767);
img = loadImage("test.png");
//image(img, 0, 0);
cities = new PVector[no_of_cities];
bestever = new PVector[no_of_cities];
for(int i=0; i<no_of_cities; )
{
xc=int(random(width));
yc=int(random(height));
c = img.get(xc,yc);
println(xc,yc,brightness(c),i);
PVector v = new PVector(xc, yc); //create points at random position
if (brightness(c) < 10){
cities = PVector.add(v); //and store it in an array
i++;
}
}
//print(cities);
}
void draw()
{
background(255);
for(int i=0; i<no_of_cities-1; i++)
{
ellipse(cities[i].x,cities[i].y,4,4); //plot the points
}
}