We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I want to start out with a window of randomly placed particles and have them generation by generation, form into the shape of an image made up of only Black and White values. The population will be different particle systems. Their "fitness score" will be based on the similarity to the target image. How do I compare the pixels in the processing window to that of an uploaded image?
Answers
So what code do you have so far? A blank sketch? A Particle class? Can you load the image?
All I have is a random particle generator.
Great! You just saved me from having to write 40 lines of particle system code so I can even START helping you. Let's run it.
...
Okay, so you have particles. They don't do much, do they? Anyway, let's just simplify that code a bit first, seeing as there's no need to pass a position if it's going to be random anyway...
Now since we need a black and white image, let's get that sorted out. And black particles are hard to see, so let's turn them red. And static ones are boring. Let's make them move a bit.
Now you said something about a generation? That's an okay approach, I guess. I'd much rather have my pixels be fit, get healthy, and reproduce lots on black areas and die quick, suffer, and be like they were in lava on white areas. But that means that each particle will need some sort of health thing going on. Add hit points!
This is very helpful, but do you know a way I could write a function that checks each pixel of the processing window to each pixel of the image and gives the number of matching pixels?
Just iterate over all the pixels in the image (you can either get() them one at a time and loop over x and y position, or you can loadPixels() and then use the pixels array directly (pixels[i] is the color of the i'th pixel)), and compare them to the pixel in the same position in your target image (again, either do img.get(x,y), or img.loadPixels(), then use img.pixels[i]). Then you're just comparing two colors. The best way to do that IMHO, is to take the red, green, and blue components of each color, and find the distance between them.
Your fitness would then be the sum of all those distances.
Hrm. My particles aren't doing as well as I would hope...
Thanks a million for all this help!! :) What does "int hp" do?