Skip to content

Commit

Permalink
actual final :)
Browse files Browse the repository at this point in the history
  • Loading branch information
PartyPackage committed Jun 11, 2023
1 parent 0b6cf5b commit 47e118d
Showing 1 changed file with 25 additions and 22 deletions.
47 changes: 25 additions & 22 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,45 @@
import colorsys


def clip(value, lower, upper):
return lower if value < lower else upper if value > upper else value


def generate_palette_hsv():
pixels = []
for x in range(256):
h = ((x % 16) / 16) * 360
s = clip((math.floor((x / 16) + 2) / 9) * 99, 0, 100)
v = clip(abs((math.floor(x / 16) - 16) / 9) * 99, 0, 100)
rgb = tuple(round(i * 255) for i in colorsys.hsv_to_rgb(h / 360, s / 100, v / 100))
pixels.append(rgb)
print(f"x: {x}, row: {math.floor(x / 16)}, hsv: {h},{s},{v}, rgb: {rgb}")

return pixels


# for reference
def unpack_rrrgggbb(uint8):
r = (uint8 & 0b11100000) >> 5
g = (uint8 & 0b00011100) >> 2
b = (uint8 & 0b00000011)
return r, g, b


# for reference
def pack_rrrgggbb(rgb: tuple):
return int(rgb[2]) + (int(rgb[1]) << 2) + (int(rgb[0]) << 5)


def clip(value, lower, upper):
return lower if value < lower else upper if value > upper else value


def generate_palette_hsv(d: int):
pixels = []
for x in range(int(math.pow(d, 2))):
h = ((x % d) / d) * 360
s = clip((math.floor((x / d) + 1) / (d / 1.5)) * 99, 0, 100)
v = clip(abs((math.floor(x / d) - d) / (d / 1.5)) * 99, 0, 100)
rgb = tuple(round(i * 255) for i in colorsys.hsv_to_rgb(h / 360, s / 100, v / 100))
pixels.append(rgb)
# print(f"x: {x}, row: {math.floor(x / 16)}, hsv: {h},{s},{v}, rgb: {rgb}")

return pixels


if __name__ == '__main__':
with Image.new('RGB', (16, 16)) as im:
pixels = generate_palette_hsv()
d = 16 # dimensions (d*d)
with Image.new('RGB', (d, d)) as im:
pixels = generate_palette_hsv(d)
for p in range(len(pixels)):
x = (p % 16)
y = int((math.floor(p / 16) / 15) * 15)
x = (p % d)
y = int((math.floor(p / d) / (d - 1)) * (d - 1))
im.putpixel((x, y), pixels[p])
#print(f"{x},{y}: {p}")
# print(f"{x},{y}: {p}")

print(len(set(im.getdata())))
im.show()

0 comments on commit 47e118d

Please sign in to comment.