I was able to get orbs to gather and create a shape by doing this:
Code:
PImage _red;
PImage _green;
PImage _aqua;
PImage _royal;
PImage _alpha;
void setup() {
size(500,500);
_red = loadImage("red.png");
_green = loadImage("green.png");
_aqua = loadImage("aqua.png");
_royal = loadImage("royal.png");
_alpha = loadImage("alpha.png");
noLoop();
smooth();
}
void draw() {
PImage[] images = new PImage[4];
images[0] = _red;
images[1] = _green;
images[2] = _aqua;
images[3] = _royal;
int smoothness = 20000;
for(int i=0; i<smoothness; i++) {
int randomImage = int(random(0,4));
int x = int(random(_alpha.width));
int y = int(random(_alpha.height));
int s = int(random(3, 7));
color pix = _alpha.get(x, y);
PImage img = images[randomImage];
if(pix == -16777216) { // if pix is black
image(img, x, y, img.width/s, img.height/s);
}
}
}
"alpha.png" is a black and white image of the shape I'm trying to create. In my case it was a "B". The variable "smoothness" determines how many orbs will make up the "B". The higher that number is the more solid or smoother the "B" looks.
Each time the for loop is processed a pixel from "_alpha" is tested to see if it's black or white. Black is the positive space that makes up the shape and white is all the background (negative) space. Orbs are only drawn on the positive space.
I've just started using processing so there might be a much easier way to accomplish this.
You wouldn't know how to take what I've shown you and then make it so that all of the orbs higher up in the image are behind all the orbs lower in the image? Creating foreshortening in a sense.