MCPcopy Create free account
hub / github.com/algorithm-archivists/algorithm-archive / chaos_game

Function chaos_game

contents/IFS/code/python/IFS.py:5–12  ·  view source on GitHub ↗
(n, shape_points)

Source from the content-addressed store, hash-verified

3
4# This generator simulates a "chaos game"
5def chaos_game(n, shape_points):
6 # Initialize the starting point
7 point = [random(), random()]
8
9 for _ in range(n):
10 # Update the point position and yield the result
11 point = [(p + s) / 2 for p, s in zip(point, choice(shape_points))]
12 yield point
13
14# This will generate a Sierpinski triangle with a chaos game of n points for an
15# initial triangle with three points on the vertices of an equilateral triangle:

Callers 1

IFS.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected