# Sesc - Programação para Ilustradores ## Criação de Retículas com Programação ## `hackmd.io/@villares/prog-ilustra-r2` - revisão rápida - grades retangulares - lendo os pixels de uma imagem - juntando as coisas - remap() - float vs. int - [Assunto avançado das máscaras...](https://hackmd.io/@villares/sesc-quadrinhos-prog-funcoes) Extra interação ```python= def setup(): size(600, 600) def draw(): fill(random_int(128), random(128, 255), 255) tamanho = random_int(20, 100) circle(mouse_x, mouse_y, tamanho) def key_pressed(): if key == ' ': background(0) ``` Escopo de variáveis (local vs. global) https://abav.lugaralgum.com/material-aulas/Processing-Python-py5/escopo_py.html https://upload.wikimedia.org/wikipedia/commons/d/dd/Adalovelace.jpg ```python= tamanho = 20 # global def setup(): global img, ar size(800, 600) #no_smooth() img = load_image('imagem.jpg') print(img.width, img.height) ar = img.width / img.height def draw(): nova_largura = mouse_x nova_altura = nova_largura / ar image(img, 0, 0, nova_largura, nova_altura) # background(200, 250, 200) # colunas = int(width / tamanho) # filas = int(height / tamanho) # print(tamanho) # for num_fila in range(filas): # y = tamanho / 2 + tamanho * num_fila # for num_col in range(colunas): # num_col 0, 1, 2 ... 19 # x = tamanho / 2 + tamanho * num_col # circle(x, y, tamanho / 2) ``` pontilismo (draw) ```python= def draw(): no_stroke() for _ in range(100): x, y = random_int(width), random_int(height) # valor_alvo = remap(valor_orginal, ini_origem, fim_origm, ini_alvo, fim, alvo) xi = int(remap(x, 0, width, 0, img.width)) yi = int(remap(y, 0, height, 0, img.height)) cor = img.get_pixels(xi, yi) fill(cor) circle(x, y, 4) ``` Versão com tamanho variável ```python tamanho = 10 # global def setup(): global img, ar size(800, 795) #no_smooth() img = load_image('imagem.jpg') # ar = img.width / img.height # print(img.width, img.height, ar) def draw(): no_stroke() background(0) colunas = int(width / tamanho) filas = int(height / tamanho) print(tamanho) for num_fila in range(filas): y = tamanho / 2 + tamanho * num_fila for num_col in range(colunas): # num_col 0, 1, 2 ... 19 x = tamanho / 2 + tamanho * num_col cor = conta_gotas(x, y, img) fill(cor) circle(x, y, tamanho) def conta_gotas(x, y, img_source): xi = int(remap(x, 0, width, 0, img_source.width)) yi = int(remap(y, 0, height, 0, img_source.height)) return img_source.get_pixels(xi, yi) def key_pressed(): global tamanho if key == '-' and tamanho > 1: tamanho = tamanho - 1 if key == '+' or key == '=': tamanho = tamanho + 1 ``` ![image](https://hackmd.io/_uploads/rJ4UKbc0a.png) --- saturado psicodélico ```python= def draw(): no_stroke() background(0) colunas = int(width / tamanho) filas = int(height / tamanho) print(tamanho) for num_fila in range(filas): y = tamanho / 2 + tamanho * num_fila for num_col in range(colunas): # num_col 0, 1, 2 ... 19 x = tamanho / 2 + tamanho * num_col cor = conta_gotas(x, y, img) m = hue(cor) b = brightness(cor) # 0 ... 255 #d = tamanho / 255 * b d = remap(b, 0, 255, 0, tamanho) color_mode(HSB) # matiz, sat, brilho fill(m, 255, 255) circle(x, y, d) ``` ![image](https://hackmd.io/_uploads/r1Km_-cRT.png) ```python= def draw(): no_stroke() background(255) colunas = int(width / tamanho) filas = int(height / tamanho) print(tamanho) for num_fila in range(filas): y = tamanho / 2 + tamanho * num_fila for num_col in range(colunas): # num_col 0, 1, 2 ... 19 x = tamanho / 2 + tamanho * num_col cor = conta_gotas(x, y, img) m = hue(cor) b = brightness(cor) # 0 ... 255 #d = tamanho / 255 * b d = remap(b, 0, 255, tamanho, 0) color_mode(HSB) # matiz, sat, brilho fill(m, 255, 128) circle(x, y, d) ``` ![image](https://hackmd.io/_uploads/S1Hiubq0p.png) --- com ellipse ```python! tamanho = 10 # global def setup(): global img, ar size(800, 795) #no_smooth() img = load_image('imagem.jpg') # ar = img.width / img.height # print(img.width, img.height, ar) def draw(): no_stroke() background(255) colunas = int(width / tamanho) filas = int(height / tamanho) print(tamanho) for num_fila in range(filas): y = tamanho / 2 + tamanho * num_fila for num_col in range(colunas): # num_col 0, 1, 2 ... 19 x = tamanho / 2 + tamanho * num_col cor = conta_gotas(x, y, img) fill(cor) # m = hue(cor) b = brightness(cor) # 0 ... 255 # #d = tamanho / 255 * b d = remap(b, 0, 255, tamanho, 0) # color_mode(HSB) # matiz, sat, brilho # fill(m, 255, 128) ellipse(x, y, d, tamanho) def conta_gotas(x, y, img_source): xi = int(remap(x, 0, width, 0, img_source.width)) yi = int(remap(y, 0, height, 0, img_source.height)) return img_source.get_pixels(xi, yi) def key_pressed(): global tamanho if key == '-' and tamanho > 1: tamanho = tamanho - 1 if key == '+' or key == '=': tamanho = tamanho + 1 ``` fundo preto ![image](https://hackmd.io/_uploads/rkJF9-9CT.png) fundo branco ![image](https://hackmd.io/_uploads/ryi-oZ9RT.png) --- ``` ellipse(x, y, d, tamanho / 2 + tamanho / 2 * sin(dist(x, y, 400, 400) / 20 + frame_count / 20)) ```