Skip to main content

2023-11-25 Bubbles

Description

Generate a circle with a randomly chosen center point, color, and radius. Continuously decrease the radius at a random rate, with a random color, and maintain the same center point to plot successive circles until the radius becomes zero. After reaching a point, start the process again.

Images

example of plotted code example of plotted code

Timelapses

Plotter Preview

preview screenshot

Code

warning

This code may or may not run and is intended more as a reference. Additionally, it was most likely not written with the latest version of the library. To ensure compatibility, check the date of this post against the version history and install the corresponding version.

from gcode2dplotterart import Plotter2D
from random import randrange, choice, randint

LINE_WIDTH = 1.0

COLORS = [
{"title": "purple1", "color": "#EABEFF"},
{"title": "blue1", "color": "#A2FFF8"},
{"title": "orange1", "color": "#FF7700"},
{"title": "purple2", "color": "#AD00FF"},
{"title": "grey1", "color": "#E9E9E9"},
]

# Create a plotter object
plotter = Plotter2D(
title="Bubbles",
x_min=0,
x_max=260,
y_min=0,
y_max=200,
feed_rate=10000,
)

for color in COLORS:
plotter.add_layer(
title=color["title"],
color=color["color"],
line_width=LINE_WIDTH,
)


counter = 0
STARTING_CIRCLES = 500

while counter < STARTING_CIRCLES:
x_center = randrange(int(plotter.x_min), int(plotter.x_max))
y_center = randrange(int(plotter.y_min), int(plotter.y_max))

min_distance_to_edge = min(
abs(x_center - plotter.x_min),
abs(plotter.x_max - x_center),
abs(y_center - plotter.y_min),
abs(plotter.y_max - y_center),
)

remaining_radius = min(randint(0, 20), min_distance_to_edge)

while remaining_radius > 0:
color = choice(COLORS)
layer = color["title"]
plotter.layers[layer].add_circle(
x_center,
y_center,
radius=remaining_radius,
)
remaining_radius -= randint(int(LINE_WIDTH), int(remaining_radius))
counter += 1


plotter.preview()

plotter.save()