/tech/ - Technology

Quam diu etiam furor iste tuus nos eludet?

Posting mode: Reply

Check to confirm you're not a robot
Drawing x size canvas

Remember to follow the rules

Max file size: 350.00 MB

Max files: 5

Max message length: 4096

Manage Board | Moderate Thread

Return | Catalog | Bottom

Expand All Images

(33.63 KB 602x500 rar 3370.png)
Newb programming question Anonymous 12/07/2017 (Thu) 10:13:10 [Preview] No. 11858

Hey guys, I wanted to write a script that will halve hex colour values and add together all possible combinations from 16 colours, making 256 colours. I suppose I could just halve the values to begin with, so really all I need to do is add hex value together to create all possible combinations. I have some python experience but still muddling through. Rare pepe for troubles.

Anonymous 12/07/2017 (Thu) 10:25:42 [Preview] No.11859 del
I don't think there is a library to do hex math directly in python. I think I need to define a hex converter, convert to int, do the sum, convert back.

Anonymous 12/08/2017 (Fri) 15:18:26 [Preview] No.11878 del
That's cool, but it's not really what I'm after. The way I think this should be handled is with 16 lists, each containing the red, green and blue value. eg:
rgb0 = [21, 21, 21]
rgb1 = [32, 32, 32]
rgb2 = [48, 48, 48]

I want to find all possible combinations of adding the values in those lists one to each other at a time. I can do one on one with numpy:
import numpy as np
np.add(rgb0, rgb0)
np.add(rgb0, rgb1)
np.add(rgb0, rgb2)
np.add(rgb1, rgb1)
np.add(rgb1, rgb2)
np.add(rgb2, rgb2)

What I think I need now is some logic to do it in sequence. I know there will be duplicates but thankfully the total combination will be 256 which is the exact number of colours in a palette. Then just to output to file.

Anonymous 12/08/2017 (Fri) 21:05:04 [Preview] No.11882 del
All done, it's fucking terrible work but it works.

Top | Return | Catalog | Post a reply