# Retículas ## `hackmd.io/@sesc-av-paulista/estudos-em-python-10-abril` - Referênca: https://abav.lugaralgum.com/material-aulas/Processing-Python-py5/reticulas.html Carrega imagem ![image](https://hackmd.io/_uploads/B1Sg6KBCke.png) ```python= def setup(): global img size(600, 400) img = load_image('piscina.png') print(img.width, img.height) if img.width > img.height: encolher = width / img.width # 600 / 800 largura_encolhida = img.width * encolher altura_encolhida = img.height * encolher margem_v = (height - altura_encolhida) / 2 margem_h = 0 else: encolher = height / img.height largura_encolhida = img.width * encolher altura_encolhida = img.height * encolher margem_v = 0 margem_h = (width - largura_encolhida) / 2 image(img, margem_h, margem_v, largura_encolhida, altura_encolhida) ``` Amostras de pixels da imagem ```python= def setup(): global img size(600, 400) img = load_image('piscina.png') def draw(): prop = width / height offset_x = mouse_x offset_y = mouse_y largura_amostra = 400 altura_amostra = largura_amostra / prop for _ in range(1000): xt = random(width) # yt = random(height) # xi = int(remap(xt, 0, width, 0, largura_amostra)) yi = int(remap(yt, 0, height, 0, altura_amostra)) cor = img.get_pixels(offset_x + xi, offset_y + yi) # int, int fill(cor) no_stroke() circle(xt, yt, 5) ``` Retícula 1 ![image](https://hackmd.io/_uploads/HkLMr5H0Jl.png) ```python! colunas = 100 def setup(): global img size(600, 400) img = load_image('piscina.png') def draw(): background(0) prop = width / height offset_x = 0 offset_y = 0 largura_amostra = 800 altura_amostra = largura_amostra / prop tam = width / colunas filas = int(height / tam) for coluna in range(colunas): for fila in range(filas): xt = coluna * tam + tam / 2 yt = fila * tam + tam/ 2 xi = int(remap(xt, 0, width, 0, largura_amostra)) yi = int(remap(yt, 0, height, 0, altura_amostra)) cor = img.get_pixels(offset_x + xi, offset_y + yi) # int, int fill(cor) no_stroke() circle(xt, yt, tam) def key_pressed(): global colunas if key == 'a': colunas += 1 elif key == 'z' and colunas > 1: colunas -= 1 ``` PB ![image](https://hackmd.io/_uploads/rykrccBCyg.png) ```python! colunas = 100 def setup(): global img size(600, 400) img = load_image('piscina.png') def draw(): background(255) prop = width / height offset_x = 0 offset_y = 0 largura_amostra = 800 altura_amostra = largura_amostra / prop tam = width / colunas filas = int(height / tam) for coluna in range(colunas): for fila in range(filas): xt = coluna * tam + tam / 2 yt = fila * tam + tam/ 2 xi = int(remap(xt, 0, width, 0, largura_amostra)) yi = int(remap(yt, 0, height, 0, altura_amostra)) cor = img.get_pixels(offset_x + xi, offset_y + yi) # int, int fill(0) no_stroke() b = 255 - brightness(cor) d = b / 240 * tam circle(xt, yt, d) def key_pressed(): global colunas if key == 'a': colunas += 1 elif key == 'z' and colunas > 1: colunas -= 1 ``` Pixelizado ![image](https://hackmd.io/_uploads/HkoXYcSR1x.png) ```python! colunas = 50 def setup(): global img size(600, 400) img = load_image('piscina.png') rect_mode(CENTER) def draw(): background(0) prop = width / height offset_x = 0 offset_y = 0 largura_amostra = 600 altura_amostra = largura_amostra / prop tam = width / colunas filas = int(height / tam) for coluna in range(colunas): for fila in range(filas): xt = coluna * tam + tam / 2 yt = fila * tam + tam/ 2 xi = int(remap(xt, 0, width, 0, largura_amostra)) yi = int(remap(yt, 0, height, 0, altura_amostra)) cor = img.get_pixels(offset_x + xi, offset_y + yi) # int, int color_mode(HSB) # matiz, sat, bri b = brightness(cor) matiz = hue(cor) #fill(matiz, 255, 255) fill(cor) no_stroke() d = b / 255 * tam square(xt, yt, tam) def key_pressed(): global colunas if key == 'a': colunas += 1 elif key == 'z' and colunas > 1: colunas -= 1 ``` Cor saturada ![image](https://hackmd.io/_uploads/S1EVjcSR1l.png) ![image](https://hackmd.io/_uploads/SkNBi9HCye.png) ```python= colunas = 150 def setup(): global img size(600, 400) img = load_image('piscina.png') rect_mode(CENTER) def draw(): background(0) prop = width / height offset_x = 0 offset_y = 0 largura_amostra = 600 altura_amostra = largura_amostra / prop tam = width / colunas filas = int(height / tam) for coluna in range(colunas): for fila in range(filas): xt = coluna * tam + tam / 2 yt = fila * tam + tam/ 2 xi = int(remap(xt, 0, width, 0, largura_amostra)) yi = int(remap(yt, 0, height, 0, altura_amostra)) cor = img.get_pixels(offset_x + xi, offset_y + yi) # int, int color_mode(HSB) # matiz, sat, bri b = brightness(cor) matiz = hue(cor) fill(matiz, 255, 255) #fill(cor) no_stroke() d = b / 255 * tam square(xt, yt, d) def key_pressed(): global colunas if key == 'a': colunas += 1 elif key == 'z' and colunas > 1: colunas -= 1 ```