distribute points
in
Programming Questions
•
1 year ago
I want to distribute a given amount of points on this image:
Atm i loop over in x and y to see if a color is black. If so i add the coordinates to a ArrayList.
Then for placing i map the point to be placed to the vector array size.
Here's a result which is not bad i think.
However, i would like to be able to use it with fewer points to place on (
detail = 15 for example), so less red points. But still be able to place a huge amount of points. Where the points don't have to be at a exact position.
They could attract like springs to find a good position.
How hard will that be and what is a good place to start?
code used:
- int dots = 20;
- ArrayList<PVector> vectors = new ArrayList<PVector>();
- void setup() {
- PImage img = loadImage("qmark.png");
- size(img.width, img.height);
- image(img, 0, 0);
- int detail = 2;
- // fill vector array with positions for points to be on
- for (int y = 0; y < height; y += detail) {
- for (int x = 0; x < width; x += detail) {
- if(get(x, y) == -16777216) {
- vectors.add(new PVector(x, y));
- }
- }
- }
- println("vectors size: "+vectors.size());
- smooth();
- }
- void draw() {
- background(255);
- // show all possible places
- for(PVector v : vectors) {
- set(int(v.x), int(v.y), color(255, 0, 0));
- }
- // draw the dots
- fill(0, 30);
- for(int i = 0; i < dots; i++) {
- int t = floor(map(i, 0, dots, 0, vectors.size()));
- PVector target = vectors.get(t);
- ellipse(target.x, target.y, 2, 2);
- }
- }
1