Skip to content

Instantly share code, notes, and snippets.

@villares
Last active October 28, 2018 01:56
Show Gist options
  • Save villares/0f12113a3a6185bcd5c7936975ad259a to your computer and use it in GitHub Desktop.
Save villares/0f12113a3a6185bcd5c7936975ad259a to your computer and use it in GitHub Desktop.
"""
ASCII video
g para salvar
a, d, w, s to change sizes
"""
add_library('video')
color_mode = False
recording = False
grid_size = 8 # tamanho da grade
font_size = 12 # tamanho dsa letras
gliphs = (
" .`-_':,;^=+/\"|)\\<>)iv%xclrs{*}I?!][1taeo7zjLu" +
"nT#JCwfy325Fp6mqSghVd4EgXPGZbYkOA&8U$@KHDBWNMR0Q"
)[::-1]
# esse [::-1] é um "reverse" do string em Python, para o primiro glifo ser o mais escuro e o último o mais claro
print(gliphs)
def setup():
global fonte, n_cols, n_rows, video
size(640, 480)
noStroke()
smooth()
rectMode(CENTER)
fonte = createFont("SourceCodePro-Bold",60)
textFont(fonte)
textAlign(CENTER, CENTER)
video = Capture(this, width, height)
# Começa a captura
video.start()
def draw():
global recording, n_rows, n_cols
n_cols = int(width / grid_size)
n_rows = int(height / grid_size)
# podemos mudar para fixar os tamanhos e
# pensar um ajuste pro entrelinhas
if video.available():
background(255)
video.read()
texto = ""
for r in range(n_rows):
y = r * grid_size
linha = ""
for c in range(n_cols):
x = c * grid_size
colour = video.get(x, y)
bri = brightness(colour)
g = int(map(bri, 0, 255, 0, len(gliphs)-1))
if color_mode: fill(colour)
else: fill(0)
textSize(font_size)
text(gliphs[g], x + grid_size / 2, y + grid_size / 2)
linha += gliphs[g]
texto += linha + "\n"
if (recording):
endRecord()
println(texto) # pro console
output = createWriter("strings.txt")
output.print(texto)
output.flush()
output.close()
recording = False
def keyPressed():
global recording, font_size, grid_size, color_mode
if key == 'g':
recording = True
if key == 'w':
font_size += 1
if key == 's' and font_size > 1:
font_size -= 1
if key == 'a':
grid_size += 1
if key == 'd' and grid_size > 1:
grid_size -= 1
if key == 'c':
color_mode = not color_mode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment