Created
January 7, 2022 22:54
-
-
Save IlievskiV/8a94d09c944b50d57260aaa646361a8b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
from operator import add | |
def generate_sierpinski_triangle(n: int): | |
sierpinski_triangle = [] # final list of points | |
# initial points | |
A = (0.0, 0.0) | |
B = (0.5, 1.0) | |
C = (1.0, 0.0) | |
triangle_vertices = [A, B, C] | |
# starting point | |
moving_point = random.choice(triangle_vertices) | |
for i in range(n): | |
offset_point = random.choice(triangle_vertices) | |
moving_point = list(map(lambda x: x / 2.0, list(map(add, moving_point, offset_point)))) | |
sierpinski_triangle.append(moving_point.copy()) | |
return sierpinski_triangle |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment