Created
July 2, 2018 13:55
-
-
Save vincentsarago/f8fe73f82e945c4bb0bebb892f0e690c to your computer and use it in GitHub Desktop.
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
# download http://soliton.vm.bytemark.co.uk/pub/cpt-city/wkp/schwarzwald/wiki-schwarzwald-cont.pg | |
with open('schwarzwald.txt') as cmap: | |
lines = cmap.read().splitlines() | |
colormap = [list(map(int, line.split())) for line in lines if not line.startswith('#')][1:] | |
new_cmap = [] | |
nb = len(colormap) | |
cmap = [[round((ix / nb) * 257), cp] for ix, cp in enumerate(colormap[::-1])] | |
for ix in range(len(cmap)): | |
cp = cmap[ix] | |
new_cmap.append(cp) | |
if ix == len(cmap) - 1: | |
continue | |
cnext = cmap[ix + 1] | |
diff = cnext[0] - cp[0] - 1 | |
if diff > 1: | |
continue | |
for ii in range(diff): | |
xc = diff | |
ycR = cnext[1][0] - cp[1][0] | |
ycG = cnext[1][1] - cp[1][1] | |
ycB = cnext[1][2] - cp[1][2] | |
mR = ycR / (diff + 1) | |
mG = ycG / (diff + 1) | |
mB = ycB / (diff + 1) | |
newId = ii + 1 | |
mC = [ | |
newId + cp[0], | |
[ | |
round(mR*newId) + cp[1][0], | |
round(mG*newId) + cp[1][1], | |
round(mB*newId) + cp[1][2], | |
] | |
] | |
new_cmap.append(mC) | |
for c in new_cmap: | |
print(f'{c[0]} {c[1][0]} {c[1][1]} {c[1][2]}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
not really proud of this scripts but it worked ;-)