Skip to content

Instantly share code, notes, and snippets.

@villares
Created August 18, 2023 14:24
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save villares/67c4f95f4c863a6115db7c50f477cd1b to your computer and use it in GitHub Desktop.
Export PNG with transparent background
# using py5 imported mode (https://py5coding.org to learn more)
def setup():
size(600, 600) # drawing size
output_canvas = create_graphics(width, height)
background(255, 0, 0) # you can turn this off, this won't be recorded!
begin_record(output_canvas) # starts recording
# output_canvas.clear() # clears pixels (not necessary in this case)
color_mode(HSB) # this needs to be inside the recording!
no_stroke() # same as with the color_mode, has to be brought here
w = 60
for j in range(10):
y = w / 2 + j * w
for i in range(10): # 0, 1, 2, ... 9
x = w / 2 + i * w
d = random(10, w)
fill(d * 3, 255, 255)
circle(x + random(-15, 15),
y + random(-15, 15), d)
end_record() # end recording
output_canvas.save(f'out.png', drop_alpha=False)
@villares
Copy link
Author

out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment