Skip to content

Instantly share code, notes, and snippets.

@jeffeb3
Last active December 8, 2022 15:26
Show Gist options
  • Save jeffeb3/478fcede199d472c661316d42d4ed9e1 to your computer and use it in GitHub Desktop.
Save jeffeb3/478fcede199d472c661316d42d4ed9e1 to your computer and use it in GitHub Desktop.
Color 0-9 grid based on jet coloring scheme to the command line
trees =[]
with open('input') as data:
for line in data:
trees.append([int(x) for x in line.strip()])
red = [[]]*10
grn = [[]]*10
blu = [[]]*10
def interp(val, xmin, ymin, xmax, ymax):
return int(255*(ymin + (val-xmin)*(ymax-ymin)/(xmax-xmin)))
for i in range(0,10):
val = float(i)/9.0
if val <= 0.125:
red[i] = 0
grn[i] = 0
blu[i] = interp(val, 0.0, 0.5, 0.125, 1.0)
elif val <= 0.375:
red[i] = 0
grn[i] = interp(val, 0.125, 0.0, 0.375, 1.0)
blu[i] = 255
elif val <= 0.625:
red[i] = interp(val, 0.375, 0.0, 0.625, 1.0)
grn[i] = 255
blu[i] = interp(val, 0.375, 1.0, 0.625, 0.0)
elif val <= 0.875:
red[i] = 255
grn[i] = interp(val, 0.625, 1.0, 0.875, 0.0)
blu[i] = 0
else:
red[i] = interp(val, 0.875, 1.0, 1.0, 0.5)
grn[i] = 0
blu[i] = 0
for row in trees:
for col in row:
color = "\033[48;2;{};{};{}m ".format(red[col], grn[col], blu[col])
print(color,end='')
print("\033[0m")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment