0% found this document useful (0 votes)
12 views1 page

Import Matplotlib - Pyplot As PLT

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views1 page

Import Matplotlib - Pyplot As PLT

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

import matplotlib.

pyplot as plt
import numpy as np

def sierpinski_triangle(ax, points, depth):


"""Genera recursivamente el Triángulo de Sierpinski."""
points = [Link](points)
if depth == 0:
triangle = [Link](points, edgecolor='black', facecolor='white')
ax.add_patch(triangle)
else:
mid1 = (points[0] + points[1]) / 2
mid2 = (points[1] + points[2]) / 2
mid3 = (points[2] + points[0]) / 2

sierpinski_triangle(ax, [points[0], mid1, mid3], depth - 1)


sierpinski_triangle(ax, [mid1, points[1], mid2], depth - 1)
sierpinski_triangle(ax, [mid3, mid2, points[2]], depth - 1)

def generate_sierpinski(depth=5):
"""Configura la figura y genera el Triángulo de Sierpinski."""
fig, ax = [Link]()
ax.set_aspect('equal')
ax.set_xticks([])
ax.set_yticks([])
ax.set_xlim(0, 1)
ax.set_ylim(0, [Link](3) / 2)

# vértices del triángulo equilátero


points = [Link]([[0.5, [Link](3) / 2], [0, 0], [1, 0]])
sierpinski_triangle(ax, points, depth)

ax.set_title(f"Triángulo de Sierpinski (profundidad {depth})")

[Link]()

You might also like