You can download this code by clicking the button below.
This code is now available for download.
This function uses the Bokeh library to draw randomly positioned circles. It accepts the center coordinates (x, y) and the radius (radius) as parameters, then generates multiple random circles and draws them onto the canvas.
Technology Stack : Bokeh, NumPy
Code Type : Graphics drawing
Code Difficulty : Intermediate
def generate_random_circle(x, y, radius):
from bokeh.plotting import figure, show
from numpy.random import random
# Create a new plot with a title and axis labels
p = figure(title="Random Circles", tools="pan,wheel_zoom,box_zoom,reset", x_axis_label='x', y_axis_label='y')
# Generate a random number of circles
num_circles = int(random() * 10) + 1
# Create random circles with random positions and radius
for _ in range(num_circles):
x0 = random() * 200 - 100
y0 = random() * 200 - 100
r = random() * 30
# Add a circle to the plot
p.circle(x0, y0, radius=r, fill_color='blue', line_color='black')
# Display the plot
show(p)