Created
February 25, 2023 20:59
-
-
Save schnittchen/6be4e24640ebe7fb5c090ff54a240748 to your computer and use it in GitHub Desktop.
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
# * grab a Gogh color scheme from https://raw.githubusercontent.com/Gogh-Co/Gogh/master/data/themes.json | |
# * split up into the `colors` and the `fbc` variable (check that the keys are | |
# in the same order!) | |
# * run this script (`elixir gogh_scheme_to_tilda_config.exs`) | |
colors = ~s{ | |
"black": "#000000", | |
"red": "#C75646", | |
"green": "#8EB33B", | |
"yellow": "#D0B03C", | |
"blue": "#72B3CC", | |
"purple": "#C8A0D1", | |
"cyan": "#218693", | |
"white": "#B0B0B0", | |
"brightBlack": "#5D5D5D", | |
"brightRed": "#E09690", | |
"brightGreen": "#CDEE69", | |
"brightYellow": "#FFE377", | |
"brightBlue": "#9CD9F0", | |
"brightPurple": "#FBB1F9", | |
"brightCyan": "#77DFD8", | |
"brightWhite": "#F7F7F7", | |
} | |
fbc = ~s{ | |
"foreground": "#F7F7F7", | |
"background": "#242424", | |
"cursorColor": "#F7F7F7" | |
} | |
defmodule Script do | |
def codes_from_lines(string) do | |
String.split(string, "\n") | |
|> Enum.filter(& &1 != "") | |
|> Enum.map(fn line -> | |
Regex.run(~r{#(..)(..)(..)}, line) | |
|> Enum.drop(1) | |
|> Enum.map(&String.to_integer(&1, 16)) | |
end) | |
end | |
def byte_to_word(byte) do | |
<<word::size(16)>> = <<byte, byte>> | |
word | |
end | |
def print_palette_line(words) do | |
IO.puts "palette = {#{Enum.join(words, ", ")}}" | |
end | |
def fbc_rgbs_to_btc_rgbs([foreground, background, cursor]) do | |
[background, foreground, cursor] | |
end | |
def print_back_text_cursor_lines(btc_rgbs) do | |
btc_rgbs | |
|> Enum.zip(~w{back text cursor}) | |
|> Enum.map(fn {[red, green, blue], role} -> | |
IO.puts "#{role}_red=#{byte_to_word(red)}" | |
IO.puts "#{role}_green=#{byte_to_word(green)}" | |
IO.puts "#{role}_blue=#{byte_to_word(blue)}" | |
end) | |
end | |
end | |
Script.codes_from_lines(colors) | |
|> Enum.flat_map(fn color -> | |
Enum.map(color, &Script.byte_to_word/1) | |
end) | |
|> Script.print_palette_line() | |
IO.puts("") | |
Script.codes_from_lines(fbc) | |
|> Script.fbc_rgbs_to_btc_rgbs() | |
|> Script.print_back_text_cursor_lines() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment