Created
January 14, 2017 04:43
-
-
Save aarqon/a7fef244b0dd44a8b951efd1a5cbc0cc to your computer and use it in GitHub Desktop.
A Python script used to generate the prettier BGR332 palette
This file contains hidden or 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
| import math | |
| import colorsys | |
| def scale(mult,step): | |
| value = (mult)*(255/step) | |
| if value % 1 > 0.5: | |
| return math.ceil(value) | |
| else: | |
| return int(value) | |
| rows = 24 | |
| columns = 0 | |
| colors = [] | |
| color_bins = [[] for _ in range(rows)] | |
| for r in range(8): | |
| for g in range(8): | |
| for b in range(4): | |
| #print(scale(r,7), scale(g,7), scale(b,3)) | |
| colors.append((scale(r,7),scale(g,7),scale(b,3))) | |
| for each in colors: | |
| (h, s, v) = colorsys.rgb_to_hsv((each[0]/255),(each[1]/255),(each[2]/255)) | |
| h_bin = int(h*rows) | |
| color_bins[h_bin].append((h,s,v)) | |
| #print((h,s,v), "put in Bin", h_bin+1) | |
| for bin in color_bins: | |
| if len(bin) > columns: | |
| columns = len(bin) | |
| sorted(bin, key=lambda color: color[2]) #Sorts each bin by v | |
| # Time to try to make the gpl file! | |
| file = open("8bit-binned.gpl",'w') | |
| file.write("""GIMP Palette | |
| Name: 8-bit Binned | |
| """) | |
| file.write("Columns: "+str(columns)+'\n') | |
| print("columns:", columns) | |
| for bin in color_bins: | |
| for each in bin: | |
| (r,g,b) = colorsys.hsv_to_rgb(each[0],each[1],each[2]) | |
| r = str(int(r*255)) | |
| g = str(int(g*255)) | |
| b = str(int(b*255)) | |
| file.write(' '.join((r,g,b,'-\n'))) | |
| file.write("0 0 0 -\n"*(columns-len(bin))) | |
| file.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment