Skip to content

Instantly share code, notes, and snippets.

@ubidefeo
Created February 22, 2024 22:48
Show Gist options
  • Save ubidefeo/9abcdab835ec07279169c54f8c17c9d0 to your computer and use it in GitHub Desktop.
Save ubidefeo/9abcdab835ec07279169c54f8c17c9d0 to your computer and use it in GitHub Desktop.
DrawBot diagonals
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
Variable([
# create a variable called 'w'
# and the related ui is a Slider.
dict(name="stroke_thickness", ui="Slider",
args=dict(
value = 6,
minValue = 1,
maxValue = 10
)
),
# create a variable called 'h'
# and the related ui is a Slider.
dict(name="dist", ui="Slider",
args=dict(
# some vanilla specific
# setting for a slider
value=1,
minValue=1,
maxValue=width() / 10
)
),
# create a variable called 'useColor'
# and the related ui is a CheckBox.
# dict(name="useColor", ui="CheckBox"),
# create a variable called 'c'
# and the related ui is a ColorWell.
# dict(name="c", ui="ColorWell")
], globals())
fill(*hex2rgb(color_a))
rect(0, 0, width(), height())
# stroke_thickness = 6
for i, v in enumerate(range(0, width() * 2)):
stroke(*hex2rgb(color_b), alpha_value *5)
strokeWidth(stroke_thickness)
line((0, i*dist), (i*dist, 0))
alpha_value -= 0.001
stroke_thickness -= .1
file_name = __file__.split('/')[-1].split('.')[0]
saveImage(f'{file_name}.mp4')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment