Last active
March 16, 2023 00:33
-
-
Save prozacchiwawa/32147abf930740e2da60aa03f193d488 to your computer and use it in GitHub Desktop.
A nice 64 color palette?
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
from PIL import Image | |
img = Image.new(mode="RGB", size=(8,8)) | |
pixels = [ ] | |
# Black | |
pixels.append((0,0,0)) | |
# Greys and white | |
for i in range(15): | |
v = int((i + 1) * (255 / 15)) | |
pixels.append((v,v,v)) | |
# Seven colors, red orange yellow green cyan blue magenta repeated 7 times at different intensities | |
def mcolor(i): | |
if i < 3: | |
lut = {0: 0, 128: 128 * ((i + 1) / 4), 255: 255 * ((i + 1) / 4)} | |
elif i == 3: | |
lut = {0: 0, 128: 128, 255: 255} | |
else: | |
lut = {0: 272 * ((i - 3) / 4.5), 128: 272 * ((i - 3) / 3.5), 255: 255} | |
def result(c): | |
l = map(lambda l: int(min(255,lut[l])), list(c)) | |
return tuple(l) | |
return result | |
for i in range(7): | |
for c in map(mcolor(i), [(255,0,0),(255,128,0),(255,255,0),(0,255,0),(0,255,255),(0,0,255),(255,0,255)]): | |
pixels.append(c) | |
final_pixels = list(map(lambda x: x[1], filter(lambda x: x[0] != 59, enumerate(pixels)))) | |
print(len(final_pixels)) | |
print(final_pixels) | |
img.putdata(final_pixels) | |
img.save('palette.png') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment