Created
October 28, 2023 23:46
-
-
Save foodini/c4dc73ef7c7536ca8e66255bb9abe2ae to your computer and use it in GitHub Desktop.
ascii mapper for shadertoy keyboard/font demo
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
#!/usr/bin/env python3 | |
# For https://www.shadertoy.com/view/XlGfzt | |
maps = [0] * 256 | |
shifts = [False] * 256 | |
#arrows | |
for i in range(16,20): | |
maps[i] = i+21 | |
#space | |
maps[ord(' ')] = 32 | |
# ! | |
maps[ord('!')] = 49 | |
shifts[ord('!')] = True | |
# " | |
maps[ord('"')] = 222 # apostrophe | |
shifts[ord('"')] = True | |
# # | |
maps[ord('#')] = 51 | |
shifts[ord('#')] = True | |
# $ | |
maps[ord('$')] = 52 | |
shifts[ord('$')] = True | |
# % | |
maps[ord('%')] = 53 | |
shifts[ord('%')] = True | |
# & | |
maps[ord('&')] = 55 | |
shifts[ord('&')] = True | |
# ' | |
maps[ord('\'')] = 222 | |
shifts[ord('\'')] = False | |
# ( | |
maps[ord('(')] = 57 | |
shifts[ord('(')] = True | |
# ) | |
maps[ord(')')] = 48 | |
shifts[ord(')')] = True | |
# * | |
maps[ord('*')] = 56 | |
shifts[ord('*')] = True | |
# + | |
maps[ord('+')] = 187 | |
shifts[ord('+')] = True | |
# , | |
maps[ord(',')] = 188 | |
shifts[ord(',')] = True | |
# - | |
maps[ord('-')] = 189 | |
shifts[ord('-')] = False | |
# . | |
maps[ord('.')] = 190 | |
shifts[ord('.')] = False | |
# / | |
maps[ord('/')] = 191 | |
shifts[ord('/')] = False | |
# 0 | |
maps[ord('0')] = 48 | |
shifts[ord('0')] = False | |
# 1-9 | |
for i in range(49,58): | |
maps[i] = i | |
shifts[i] = False | |
# : | |
maps[ord(':')] = 186 | |
shifts[ord(':')] = True | |
# ; | |
maps[ord(';')] = 186 | |
shifts[ord(';')] = False | |
# < | |
maps[ord('<')] = 188 | |
shifts[ord('<')] = True | |
# = | |
maps[ord('=')] = 187 | |
shifts[ord('=')] = False | |
# > | |
maps[ord('>')] = 190 | |
shifts[ord('>')] = True | |
# ? | |
maps[ord('?')] = 191 | |
shifts[ord('?')] = True | |
# @ | |
maps[ord('@')] = 50 | |
shifts[ord('@')] = True | |
# A-Z | |
for i in range(65,91): | |
maps[i] = i | |
shifts[i] = True | |
# [ | |
maps[ord('[')] = 219 | |
shifts[ord('[')] = False | |
# \ | |
maps[ord('\\')] = 220 | |
shifts[ord('\\')] = False | |
# ] | |
maps[ord(']')] = 221 | |
shifts[ord(']')] = False | |
# ^ | |
maps[ord('^')] = 54 | |
shifts[ord('^')] = True | |
# _ | |
maps[ord('_')] = 189 | |
shifts[ord('_')] = True | |
# ` | |
maps[ord('`')] = 192 | |
shifts[ord('`')] = False | |
# a-z | |
for i in range(97,123): | |
maps[i] = i-32 | |
shifts[i] = False | |
# { | |
maps[ord('{')] = 219 | |
shifts[ord('{')] = True | |
# | | |
maps[ord('|')] = 220 | |
shifts[ord('|')] = True | |
# } | |
maps[ord('}')] = 221 | |
shifts[ord('}')] = True | |
# ~ | |
maps[ord('}')] = 192 | |
shifts[ord('}')] = True | |
# Shift | |
maps[167] = 16 ## | |
shifts[167] = False | |
# Backspace | |
maps[2] = 46 ## "Backward play symbol" | |
shifts[2] = False | |
# Del | |
maps[5] = 8 ## "Forward play symbol" | |
shifts[5] = False | |
# Tab | |
maps[20] = 9 ## "double-ended Left/right arrow" | |
shifts[20] = False | |
# Enter | |
maps[182] = 13 ## "Paragraph symbol | |
shifts[182] = False | |
# Ctrl | |
maps[199] = 17 # Diacritical C | |
shifts[199] = False | |
# LEFT Alt | |
maps[192] = 91 # Diacritical A | |
shifts[192] = False | |
# RIGHT Alt | |
maps[193] = 93 # Diacritical A | |
shifts[193] = False | |
# Esc | |
maps[200] = 27 # Diacritical E | |
shifts[200] = False | |
# PgUp | |
maps[0] = 33 # Previous Track | |
shifts[0] = False | |
# PgDn | |
maps[8] = 34 # Next Track | |
shifts[8] = False | |
# End | |
maps[187] = 35 # fast fwd | |
shifts[187] = False | |
# Home | |
maps[171] = 36 # fast rev | |
shifts[171] = False | |
comments = {} | |
comments[0] = '0: Prev Track' | |
comments[16] = '16: left arrow' | |
comments[32] = '32: space' | |
comments[48] = '48: 0' | |
comments[64] = '64: @' | |
comments[80] = '80: P' | |
comments[96] = '96: `' | |
comments[112] = '112: p' | |
comments[128] = '128: alpha' | |
comments[144] = '144: GAMMA' | |
comments[160] = '160: undefined?' | |
comments[176] = '176: degree?' | |
comments[192] = '192: Diacritical A' | |
comments[208] = '208: Diacritical D' | |
comments[224] = '224: Diacritical a' | |
comments[240] = '240: Diacritical delta' | |
print('uint ascii_to_keycode_map[64] = uint[64](') | |
for i in range(0,256,4): | |
if i in comments: | |
print('\t//', comments[i]) | |
if i%16 == 0: | |
print('\t', end='') | |
val = (maps[i]<<24) | (maps[i+1]<<16) | (maps[i+2]<<8) | (maps[i+3]) | |
print(str.format('0x%08Xu' % val), end='') | |
if(i != 252): | |
print(', ', end='') | |
if i%16 == 12: | |
print('') | |
print(');\n') | |
print('uint ascii_to_keycode_shift_map[8] = uint[8](') | |
for i in range(0,256,32): | |
if i in comments: | |
print('\t//', comments[i]) | |
print('\t', end='') | |
val = 0 | |
for j in range(32): | |
val <<= 1 | |
if shifts[i+j]: | |
val += 1 | |
print(str.format('0x%08Xu' % val), end='') | |
if(i != 224): | |
print(',', end='') | |
print() | |
print(');') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment