We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi All,
I do have a code for a voronoi pattern. Now i want to modify this where i can use predefined points (x and y axis). Is there somebody who can help me with this.
Thanks
` int i = 0;`
int myw = 250;
int myh = 250;
int ncolors = 6;
int[] seeds_x = new int[ncolors];
int[] seeds_y = new int[ncolors];
color[] seed_colors = new color[ncolors];
int minDistance = 0;
int minIndex = 0;
void setup()
{
background(255);
size(250, 250);
smooth();
seed_colors[0] = color(255, 0, 0);
seed_colors[1] = color(0, 255, 0);
seed_colors[2] = color(0, 0, 255);
seed_colors[3] = color(255, 255, 0);
seed_colors[4] = color(255, 0, 255);
seed_colors[5] = color(0, 255, 255);
for(i=0; i < ncolors; i = i+1)
{
seeds_x[i] = random(20, myw - 20);
seeds_y[i] = random(20, myh - 20);
}
}
void draw()
{
for(int px = 0; px < myw; px = px +1) {
for(int py = 0; py < myh; py = py +1) {
minDistance = ((px - seeds_x[0]) * (px - seeds_x[0])) + ((py - seeds_y[0]) * (py - seeds_y[0]));
minIndex = 0;
for (int nc = 1; nc < ncolors; nc = nc+1){
int dist = ((px - seeds_x[nc]) * (px - seeds_x[nc])) + ((py - seeds_y[nc]) * (py - seeds_y[nc]));
if (dist <= minDistance) {
minDistance = dist;
minIndex = nc;
}
}
stroke(seed_colors[minIndex])
point(px, py);
}
}
}
Answers
question unclear
elaborate
Previous posts: https://forum.processing.org/two/search?Search=voronoi
Kf
What are your defined points, or where are they coming from?
Currently, you are randomizing your seeds here:
...and if you had an array of PVectors that defined your data, instead you would be setting them like this: