Hey, so the question might be very confusing, but its actually pretty simple^^ What i would like to do, is to write a program that has an unspecified number of Points (1-20 or so… maybe more) that all maintain a certain distance to each other. I already had something that worked, but only for keeping distance to 1 point… all the other points just merged together and did only care for the distance to the main point (which is controlled by mousePosition). Now the problem is, that i cant make it only dependent on distance to each other… What i did until now was to change the color of each pixel base on the distance of it to each point i have. And that each Point changes its own position based on the pixels 1 above, left, right and below itself. First of all, this colorcoding was pretty useless, since the total of color “added” to each pixel equals to 282 (dist from 0,0 to 200, 200) which means that its basically useless…(imagine you have distances from 0-10. At 0 dist is 0, at 10 it is 10, but for a point that starts at 10, 10 is 0 and 0 is 10. Now add each point across this line and you end up with each point having 10…) so i map the value after adding them for each point (i do this for each pixel) to a range from 0 to 1 and the apply a sinus curve that i made to make it a waterfall like change and remap it again frm 0 to 1 to 0 to 255 (i also tried to map them using color to be more precise, becaue pixels red only gives me ints and is pretty unprecise and doesn’t work well… and after the image is done i look for each points position up down left and right positions and move them in the direction that has the color closest to 20, when i used red(), and something -10million with color(), but it moves weird… btw, the sin curve i used is :
color1 = (sin(color1 * PI + (0.5 * PI)) / 2) + 0.5; you can just use it again afterwards to make the change be sharper. Now i tried everything, but i’m getting so confused and i’d like to ask if someone knows a better way to achive what i’m looking for that doesn’t require to use color, or if someone can do this better, or give me some help regarding this… i can also include the code i got until now, but it honestly has become a giant mess, after i changed and tried so much, that it just doesn’t show much… somewhere inbetween i also got a fractal image even though i don’t know why xD… so every help is very appreciated^^
Point[] p = new Point[3];
void setup() {
size(100, 100);
for (int i = 0; i < p.length; i++) {
p[i] = new Point(50+10*i, 50);
}
p[0].update = false;
}
void draw() {
background(255);
p[0].setPos(mouseX, mouseY);
for (int i = 0; i < p.length; i++) {
p[i].bUpdate();
}
loadPixels();
for (int i = 0; i < p.length; i++) {
pixels[p[i].y*width+p[i].x] = color(0);
}
updatePixels();
}
class Point {
int x;
int y;
boolean update = true;
Point(int x_, int y_) {
x = x_;
y = y_;
}
void bUpdate() {
if (update) {
float[] force = new float[4];
for (int i = 0; i < p.length; i++) {
force[0] += dist(x, y-1, p[i].x, p[i].y);
force[1] += dist(x, y+1, p[i].x, p[i].y);
force[2] += dist(x-1, y, p[i].x, p[i].y);
force[3] += dist(x+1, y, p[i].x, p[i].y);
}
if (force[0] < force[1] && force[0] > 20 * p.length) {
y -= 1;
} else if (force[1] < force[0] && force[1] > 20 * p.length) {
y += 1;
} else if (force[0] > force[1] && force[0] < 20 * p.length) {
y -= 1;
} else if (force[1] > force[0] && force[1] < 20 * p.length) {
y += 1;
}
if (force[2] < force[3] && force[2] > 20 * p.length) {
x -= 1;
} else if (force[3] < force[2] && force[3] > 20 * p.length) {
x += 1;
} else if (force[2] > force[3] && force[2] < 20 * p.length) {
x -= 1;
} else if (force[3] > force[2] && force[3] < 20 * p.length) {
x += 1;
}
}
}
void setPos(int x_, int y_) {
x = x_;
y = y_;
}
}
Thats how it looks more or less (at least its readable). I remade it whole and it still has the same problem… The second and third points just always get too close together… They should also keep the same distance to each other as to the main Point…