Skip to content

Instantly share code, notes, and snippets.

@ubidefeo
Created February 22, 2024 22:49
Show Gist options
  • Save ubidefeo/ddd291379eddbba071a7fe01521dac26 to your computer and use it in GitHub Desktop.
Save ubidefeo/ddd291379eddbba071a7fe01521dac26 to your computer and use it in GitHub Desktop.
DrawBot Grid
from time import sleep
start_w = 400
start_h = 400
color_a = 0xf78ae0
color_b = 0x5cc9f5
alpha_value = 1.0
square_w = 30
square_h = 30
cols = int(start_w / square_w)
rows = int(start_h / square_h)
next_x = 0
next_y = 0
size(cols * square_w, rows * square_h)
fill(1,1,1)
rect(0, 0, width(), height())
def hex2rgb(hex_color):
# h = hex.lstrip('#')
# RGB = tuple(int(h[i:i+2], 16) for i in (0, 2 ,4))
# RGB = tuple(hex >> 16 & 0xff, hex >> 8 & 0xff, hex & 0xff)
# r1, g1, b1 = RGB[0] / 255, RGB[1] / 255, RGB[2] / 255
r = (hex_color >> 16 & 0xff) / 255
g = (hex_color >> 8 & 0xff) / 255
b = (hex_color & 0xff) / 255
return r, g, b
def cut_square(x, y, w, h, c, o):
stroke(*hex2rgb(color_b), alpha_value)
strokeWidth(3 * alpha_value)
fill(*hex2rgb(c), alpha_value)
rect(x, y, w, h)
if o == 'l':
line((x + w, y), (x, y + h))
else:
line((x, y), (x + w, y + h))
for i, v in enumerate(range(0, rows * cols)):
if i%(width() / square_w) == 0 and i != 0:
next_y += square_h
next_x = 0
alpha_value -= 0.05
cut_square(next_x, next_y, square_w, square_h, color_a, 'l' if i % 2 else 'r')
next_x += square_w
file_name = __file__.split('/')[-1].split('.')[0]
saveImage(f'{file_name}.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment