Im trying to make something like that:
I already made dots generation and border circle…but i dont know how to connect all dots between…i need to connect every dot to closest dots…i tried that myself but i got an OutOfBounds exception…
There is code:
//custom method imports
CustomMath math = new CustomMath();
//variable assigment
int intotal = (int)random(25, 50);
int sidetotal = (int)random(10, 20);
int circles = 0;
int i = 0;
float r;
//arrays assgiment
PVector[] temp = new PVector[0];
PVector[] coords = new PVector[0];
PVector[] circle = new PVector[0];
int[] temp2 = new int[0];
void setup() {
size(displayWidth, displayHeight);
if(width > height) {
r = width / TWO_PI;
} else {
r = height / TWO_PI;
}
background(0);
translate(width/2, height/2);
noFill();
stroke(100, 255, 0);
strokeWeight(3);
ellipse(0, 0, r * 2.25 ,r * 2.25);
drawCircle(sidetotal, (r * 2.25)/2);
beginShape();
while (i < intotal) {
float x = random(-r, r);
float y = random(-r, r);
int closest = 0;
double d = (double)x * (double)x + (double)y * (double)y;
if (d < (double) r * (double) r) {
circles++;
int weight = (int)math.compareTo(random(10, 20), intotal, intotal * HALF_PI);
strokeWeight(weight);
temp = (PVector[])append(temp, new PVector(x, y));
for(int n = 0; n < temp.length-1; n++) {
temp2 = (int[])append(temp2, (int)dist(x, y, temp[n].x, temp[n].y));
}
if(temp2.length != 0) {
closest = min(temp2);
}
temp2 = new int[0];
if(closest - weight*2 > 10) {
point(x, y);
coords = (PVector[])append(coords, new PVector(x, y));
i++;
}
}
}
endShape();
connect(coords, circle);
}
void draw() {
}
void drawCircle(float sides, float r)
{
noFill();
beginShape(POINTS);
for (int i = 0; i < sidetotal; i++) {
int weight2 = (int)math.compareTo(random(15, 25), intotal, intotal * HALF_PI);
strokeWeight(weight2);
float angle = 360 / sides + random(15, 20);
float x = cos(radians(i * angle )) * r;
float y = sin(radians(i * angle )) * r;
point(x, y);
circle = (PVector[])append(circle, new PVector(x, y));
}
endShape();
}
void connect(PVector[] inner,PVector[] outer) {
PVector[] temp;
PVector[] temp2;
for(int i = 0; i < inner.length-1; i++) {
temp = sortPVectorArray(inner[i], inner);
temp2 = sortPVectorArray(inner[i], outer);
for(int u = 0; u < temp.length-1; i++) {
//that line
if(dist(inner[i].x, inner[i].y, temp[u].x, temp[u].y) > 10) {
beginShape();
line(inner[i].x, inner[i].y, temp[u].x, temp[u].y);
endShape();
}
}
for(PVector vector1 : outer) {
}
}
}
PVector[] sortPVectorArray(PVector position, PVector[] positions) {
for(int i = 0; i < positions.length; i++) {
// Loops through positions
// Make sure i is not 0 as positions[positions.length] is out of bounds
if(i != positions.length-1) {
while (PVector.dist(positions[i+1], position) < PVector.dist(positions[i], position)) {
PVector temp1 = positions[i+1]; // Assign temp variables
PVector temp2 = positions[i]; positions[i] = temp1;
positions[i+1] = temp2; // Swap them around
}
}
}
return positions;
}
CustomMath class:
public class CustomMath {
float compareTo(float to,float from, float max) {
return from/max*to;
}
}