Created
March 10, 2016 22:19
-
-
Save hexmoire/bc0eeed8131afda2aaae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* | |
* every 24 bit color | |
* | |
* this sketch will generate and on left click, compress and save a fairly | |
* large image. if you have doubts about anything, save your work before | |
* running it. | |
* | |
* coded in Processing 3.0 IDE | |
* i appreciate a mention/link back in derivative works | |
* | |
* hexmoire / michael mcknight | |
* http://hexmoire.tumblr.com/ | |
* | |
* this is cleaned up code, not a representation of the mess | |
* i make while developing an idea. | |
* the original code generated the gif at: | |
* http://hexmoire.tumblr.com/post/140769217889/goal-put-every-24-bit-rgb-color-in-one-image | |
* | |
*/ | |
PGraphics all; | |
int index; | |
void setup(){ | |
//initialize the variable to be used as an index to our array of pixels. | |
index=0; | |
//make a very large image that has the exact number of pixels we're looking for. | |
all = createGraphics(4096,4096); | |
//our display, which will show a narrow view into what's generated. | |
size(600,600,P2D); | |
//printing verification that the number of pixels will indeed equal | |
//the number of colors in a 3 channel, 8 bits per pixel colorspace. | |
int a=256*256*256; | |
int b=256*16; | |
int c = b*b; | |
println(a+" "+b); | |
println(a==c); | |
} | |
//translating array indices to 24 bit color. | |
int iColor(int c){ | |
//keep the alpha channel opaque. | |
return 0xff000000 | c; | |
} | |
void draw(){ | |
//initialize display for this frame. | |
background(0); | |
//if image is done generating | |
//save and exit on left mouse click. | |
if(index>=4096*4096){ | |
if(mousePressed){ | |
if(mouseButton == LEFT){ | |
println("saving"); | |
all.save("test.png"); | |
exit(); | |
} | |
} | |
} | |
//if image is *not* done generating, continue generating | |
//for about 1/30 of a second. | |
else{ | |
//track time started | |
int tm = millis(); | |
//get "all" ready for pixel operations. | |
all.beginDraw(); | |
all.loadPixels(); | |
//set pixels and increment index until 33 ms have passed . | |
for( ; index<all.pixels.length && millis() < tm+33 ; index++ ){ | |
all.pixels[index] = iColor(index); | |
} | |
//update "all" graphics. | |
all.updatePixels(); | |
all.endDraw(); | |
//show progress. | |
println("generated up to pixel "+index); | |
if (index==4096*4096){ | |
println("done generating."); | |
} | |
} | |
//transform mouse coordinates to "all" coordinates, | |
//adjusting for width and height of display. | |
int sX = mouseX*(all.width-width)/width; | |
int sY = mouseY*(all.height-height)/height; | |
//copy a rectangle of pixels from "all" to the display, | |
//using mouse position to pan. | |
copy(all,sX,sY,width,height,0,0,width,height); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment