-
-
Save gcrsaldanha/c2c2a7bcb745ee4882eb08bbfe13ac36 to your computer and use it in GitHub Desktop.
# Para mais conteúdos de Python, acesse: https://instagram.com/gabrielsaldanha.dev | |
# É necessário ter Pillow instalado: | |
# $ python3 -m pip install Pillow | |
from PIL import Image, ImageDraw, ImageFont | |
image = Image.new("RGB", (1080, 1080), color=(41, 46, 48)) | |
img_draw = ImageDraw.Draw(image) | |
# Arquivo de fonte Helvetica.ttc deve estar no mesmo diretório | |
# que o programa está sendo executado | |
font = ImageFont.truetype("Helvetica.ttc", size=72) | |
def main(): | |
title = "Essa imagem\n\nfoi feita\n\nem Python" | |
img_draw.text((300, 405), title, font=font, fill=(234, 234, 235)) | |
seq = log_seq(end=270, points=30) | |
for i in seq: | |
xy0 = (i, i) | |
xy1 = 1080 - i - 1, 1080 - i - 1 | |
img_draw.rectangle([xy0, xy1], width=2) | |
image.save("img.png") | |
def log_seq(end, points): | |
""" | |
Retorna uma sequência de pontos normalizada em relação a `end`. | |
O tamanho da sequência é determinada por `points`. | |
Utilizamos a função logarítmica para obter a distância entre os pontos. | |
""" | |
from math import log | |
seq = [] | |
for i in range(points): | |
seq.append(log(i + 1)) | |
norm_factor = end / seq[i] # Normaliza os valores | |
return [norm_factor * point for point in seq] | |
main() |
import matplotlib.pyplot as plt
import matplotlib.patches as patches
def draw_block(ax, x, y, width, height, label):
rect = patches.Rectangle((x, y), width, height, linewidth=1, edgecolor='black', facecolor='none')
ax.add_patch(rect)
ax.text(x + width/2, y + height/2, label, ha='center', va='center', fontsize=8)
fig, ax = plt.subplots(figsize=(12, 8))
block_width = 3
block_height = 1
subblock_height = block_height / 3
subsubblock_height = subblock_height / 2
Draw the blocks
x_start = 1
y_start = 8
for i, ce in enumerate(['0.3 dS m-1', '3.0 dS m-1']):
x = x_start
y = y_start - i * (block_height + 0.5)
draw_block(ax, x, y, block_width, block_height, f'CEa: {ce}')
for j, dose in enumerate(['0 t ha-1', '10 t ha-1', '20 t ha-1']):
y_sub = y - j * subblock_height
draw_block(ax, x + block_width, y_sub, block_width, subblock_height, f'Dose: {dose}')
for k, inoc in enumerate(['Inoculação', 'Não Inoculação']):
y_subsub = y_sub - k * subsubblock_height
draw_block(ax, x + 2 * block_width, y_subsub, block_width, subsubblock_height, inoc)
ax.set_xlim(0, 10)
ax.set_ylim(0, 10)
ax.axis('off')
plt.show()
import matplotlib.pyplot as plt
import matplotlib.patches as patches
def draw_block(ax, x, y, width, height, label):
rect = patches.Rectangle((x, y), width, height, linewidth=1, edgecolor='black', facecolor='none')
ax.add_patch(rect)
ax.text(x + width/2, y + height/2, label, ha='center', va='center', fontsize=8)
fig, ax = plt.subplots(figsize=(12, 8))
block_width = 3
block_height = 1
subblock_height = block_height / 3
subsubblock_height = subblock_height / 2
Draw the blocks
x_start = 1
y_start = 8
for i, ce in enumerate(['0.3 dS m-1', '3.0 dS m-1']):
x = x_start
y = y_start - i * (block_height + 0.5)
draw_block(ax, x, y, block_width, block_height, f'CEa: {ce}')
for j, dose in enumerate(['0 t ha-1', '10 t ha-1', '20 t ha-1']):
y_sub = y - j * subblock_height
draw_block(ax, x + block_width, y_sub, block_width, subblock_height, f'Dose: {dose}')
for k, inoc in enumerate(['Inoculação', 'Não Inoculação']):
y_subsub = y_sub - k * subsubblock_height
draw_block(ax, x + 2 * block_width, y_subsub, block_width, subsubblock_height, inoc)
ax.set_xlim(0, 10)
ax.set_ylim(0, 10)
ax.axis('off')
plt.show()
from PIL import Image, ImageDraw, ImageFont