谢尔宾斯基的三角Pygame递归函数

问题描述

我一直在研究指导文件,我们打算创建一个Sierpinksi三角形。应该看起来像这样: enter image description here

我不知道我的代码出了什么问题,导致它与我想要的输出不一样。有人可以帮我解决这个问题吗?

我无法执行我的功能。

import sys,pygame


# a function that will draw a right-angled triangle of a given size anchored at a given location
def draw_triangle(screen,x,y,size):
    pygame.draw.polygon(screen,white,[[x,y],[x + size,[x,y - size]])

############################################################################################# 
# Define a function that will draw Sierpinski's Triangle at a given size anchored at a given location
# You need to update this function 
# currently only one triangle is drawn

def sierpinski(screen,size):
    mini_size = 10

    if size < mini_size:
        return draw_triangle(screen,size)
    else:

        new_size = int(size * 0.5)
        sierpinski(screen,x + new_size,new_size)
        sierpinski(screen,y - new_size,x - new_size,y + new_size,new_size)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)