Code To Generate Alpha Patterns From Image
Reply
j0n111
Advanced
|
2 years, 9 months ago by j0n111
i made this code using processing. it takes in an image and spits out a complete alpha pattern fit for this site. it also spits out the accompanying hex and rgb values for each letter. feel free to use this code! i don't mind if you post the code elsewhere as long as you add in the credit! happy patterning ๐/******************************************************************************* * Code By: Joni Brooks Insta: j0n1_br00k5 * *******************************************************************************/ PImage pic; void setup() { size(500,500); //input your image's name (place image in file's folder) pic = loadImage("smallButtons1To8Glow.png"); int firstNum = 0; //change 0 to whatever pixel you want the code to start from //picture width and height int pW = pic.width; int pL = pic.height; //incrementers used to keep track of sets of pixel rgb values int letterIncrement = 0; int inc = 0; int letterTester = 0; //holds max loop value so rgb values can be checked against all previously printed pixels int colorLetter = 97; //ascii code for lowercase letters starting from 'a' int pixVal[] = new int[500]; //holds 250 individual rgb values + their assigned ascii code. FOR BRACELETBOOK, ONLY [104] SPACES ARE USABLE char pixLabel[] = new char[pW*pL]; //holds the char assigned to each pixel pic.loadPixels(); //loops through every pixel starting from firstNum for (int picPix = firstNum; picPix < pic.width * pic.height; picPix++) { //sets the rgb values of pixel number picPix int r = int(red(pic.pixels[picPix])); int g = int(green(pic.pixels[picPix])); int b = int(blue(pic.pixels[picPix])); //primes the comparison array with the first pixel's rgb values if(picPix == firstNum) { pixVal[0] = r; pixVal[1] = g; pixVal[2] = b; } //compares the current pixel's rgb values to all previous pixel's rgb values for(int y = 0; y <= letterTester; y++) { //if the pixel's rgb values = a previous set of values... if(r == pixVal[0+(4*y)] && g == pixVal[1+(4*y)] && b == pixVal[2+(4*y)]) { //assigns letter to documented but unassigned rgb values if(pixVal[3+(4*y)] == 0) pixVal[3+(4*y)] = colorLetter; //assigns this pixel the letter already assigned to this set of values pixLabel[picPix] = char(pixVal[3+(4*y)]); break; } else //this set of values does not match with previous ones { //if this set of rgb values has never been seen, assign it an ascii code letter if( y == letterTester) { ++letterIncrement; pixLabel[picPix] = char(++colorLetter); pixVal[0+(4*letterIncrement)] = r; pixVal[1+(4*letterIncrement)] = g; pixVal[2+(4*letterIncrement)] = b; pixVal[3+(4*letterIncrement)] = colorLetter; } } } //makes sure the loop is able to cycle through all of the sets of values letterTester = letterIncrement; //prints each letter print(pixLabel[picPix]); //starts a new line to match letters up with their pixels if(picPix != 0)if((picPix % pW) == pW - 1)println(); } //key for letters to hex code to rgb values for each different color of pixels for(int counter = 0; counter < 100; counter++) { if(pixVal[3+(4*inc)] != 0) { color c = color(pixVal[0+(4*inc)], pixVal[1+(4*inc)], pixVal[2+(4*inc)] ); println(char(pixVal[3+(4*inc)]), " = ", hex(c, 6), " = ", pixVal[0+(4*inc)], ",", pixVal[1+(4*inc)],",", pixVal[2+(4*inc)]); inc++; } else break; } } void draw () { image(pic, 0, 0); } |
j0n111
Advanced
|
2 years, 9 months ago by j0n111
so if you have pixel art, you can pretty much instantly make a full pattern of it. i have no clue if this tool already exists elsewhere; im hot garbage at looking for stuff lol
|
halokiwi
Moderator
|
2 years, 9 months ago by halokiwi
I've got no idea about programming, but this sounds cool. What advantages or disadvantages does it have to "alpha from image" in the alpha pattern generator? Because if I understand it correctly, this does the same thing. You put a photo in and it turns it into an alpha pattern.
|
j0n111
Advanced
|
2 years, 9 months ago by j0n111
if the picture you input in the code is the basic Alpha from the default alpha bracelet pattern, the code would give you this:aaaaaaaaaaaaaaaaaaaaaaaaaaa aabbbaabaaaaaaabaaaaaaaaaaa abaaababaaaaaaabaaaaaaaaaaa abaaabababbbbaababbaaabbbaa abbbbbababaaababbaabaaaaaba abaaabababaaababaaabaabbbba abaaabababbbbaabaaababaaaba abaaabababaaaaabaaabaabbbba aaaaaaaaabaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaa a = 383838 = 56 , 56 , 56 b = FF4400 = 255 , 68 , 0 this looks janky but the text wall is the full alpha pattern. the only change needed for any image is the name of the image itself |
halokiwi
Moderator
|
2 years, 9 months ago by halokiwi
So it does what alpha from image does but can also give you rgb values of the colours?
|
j0n111
Advanced
|
2 years, 9 months ago by j0n111
it also has no dimension limit and tells you exactly what the colors in the image are
|
j0n111
Advanced
|
2 years, 9 months ago by j0n111
i'm not really sure how alpha from image works so idk how the tools compare with one another ๐ค
|
j0n111
Advanced
|
2 years, 9 months ago by j0n111
ohhh! i messed around with alpha from image a bit more and yeah, our two tools are basically the same. the only change of note mine has is that only the image is accepted (wont except user imputed dimensions or color amounts) for the the final output. if i'd looked around for like 2 minutes longer i would've saved myself hours making this ๐ญ oh the pain of being hot garbage at looking for stuff ๐ |
Reply