Random Walks 1

num_paths = 4000
filter_vertical_departures = True
scene.background = Gray(0)
scene.viewport = (1 m, 1 m)
# for each path
while len(scene.items) < num_paths:
path = Path(color=random.color_rgb(), line_width=1 mm, opacity=0.25)
# start at the center, with a random heading
p = Point(0, 0)
path.move_to(p)
heading = random( ± 180° )
while scene.viewport.contains(p):
heading += random( ± 10° )
p += Point(xy_heading=heading, radius=1 cm)
path.line_to(p)
if filter_vertical_departures and not scene.viewport.contains_y(p.y):
scene.remove(path)