I wish to take an image 100x300 pixels.
Easy so far!
Analyze each pixel for its RGB value and store it in an array.
No need! That's what an image is already! Let's skip this step.
Then from this array I want to produce images that are based on the permutations of this array.
Whoa, that's... that's a lot of permutations...
Now since 100x300 pixels would be a total of 30,000 pixels and the permutations
Yeah, lots...
of that array where order does count and repetition is not allowed would be 30,000 factorial
Lots!
the amount of new images produced would be incredible.
Yes, literally beyond belief.
But is this feasible?
Yes, but I don't know why you'd want to. Let me explain...
30,000! is a big number. Very big. Heck, even 52! is a big number. 52! is so big that, if you shuffled a deck of cards, chances are that NO ONE has EVER shuffled the deck into the same order, ANYWHERE, SINCE THE DAWN OF TIME. And 30,000! is WAY bigger than 52!
So... why bother with permutations at all? You could literally just place each of the 30,000 pixels AT RANDOM, and chances are good (VERY, VERY, VERY GOOD) that you would generate a unique image. And you could probably do this a billion times and still never get the same pattern twice.
- PImage img;
- int[] pos;
- void setup() {
- size(300, 100);
- img = loadImage("http://www.madisonsquarechurch.org/wp-content/uploads/2012/11/EASTER-1-300x100.jpg");
- pos = new int[width*height];
- for ( int i=0;i<pos.length;i++) {
- pos[i] = i;
- }
- randomize();
- }
- void draw() {
- int i=0;
- loadPixels();
- for ( int x=0; x<width;x++) {
- for (int y=0; y<height;y++) {
- pixels[pos[i]] = img.get(x, y);
- i++;
- }
- }
- updatePixels();
- noLoop();
- }
- void randomize() {
- int t=0, r;
- for ( int i=0;i<pos.length;i++) {
- r = int(random(i, pos.length-1));
- t = pos[i];
- pos[i] = pos[r];
- pos[r] = t;
- }
- }
- void keyPressed() {
- randomize();
- redraw();
- }
- void mousePressed(){
- randomize();
- redraw();
- }
Also, generating permutations of things in order is a pain in the ass. Yeah.