find random points within irregular shape
in
Programming Questions
•
2 years ago
hello there
I am trying to write a program which can find random points within a given shape and then draw shapes to them. Eventually, this is with a view to creating print pieces so the final resolution will be quite high.
I have written the program below which uses a black and white .jpeg (in this case a letter A) as the shape template. The program identifies black pixels in the image, stores the X and Y co-ordinates to separate arrays which i then access randomly to find points.
It works fine but quite slowly at size(300, 300). bearing in mind i am eventually aiming to output 300dpi A3 images i was wondering whether there is a more efficient way to achieve the same result.
hope this makes sense.
thanks
I am trying to write a program which can find random points within a given shape and then draw shapes to them. Eventually, this is with a view to creating print pieces so the final resolution will be quite high.
I have written the program below which uses a black and white .jpeg (in this case a letter A) as the shape template. The program identifies black pixels in the image, stores the X and Y co-ordinates to separate arrays which i then access randomly to find points.
It works fine but quite slowly at size(300, 300). bearing in mind i am eventually aiming to output 300dpi A3 images i was wondering whether there is a more efficient way to achieve the same result.
hope this makes sense.
thanks
- PImage A;
int[] xPos = new int[0];
int[] yPos = new int[0];
void setup() {
size(300,300);
A = loadImage("A.jpg");
A.loadPixels();
rectMode(CENTER);
noLoop();
}
void draw() {
for (int x= 0; x< A.width; x++) {
for (int y = 0; y < A.height; y++) {
if (A.pixels[(A.width*y)+x] == color(0,0,0)) {
xPos = append(xPos, x);
yPos = append(yPos, y);
}
}
}
for (int i = 0; i <200; i++) {
int myNum = int(random(xPos.length));
rect(xPos[myNum], yPos[myNum], 20, 20);
}
}
1
