【发布时间】:2019-09-22 12:20:39
【问题描述】:
我正在尝试在 Python 中创建如下所示的三角形镶嵌:
我得到的只是谢尔彭斯基的三角形。我假设它会使用一些相同的代码。
import turtle as t
import math
import colorsys
t.hideturtle()
t.speed(0)
t.tracer(0,0)
h = 0
def draw_tri(x,y,size):
global h
t.up()
t.goto(x,y)
t.seth(0)
t.down()
color = colorsys.hsv_to_rgb(h,1,1)
h += 0.1
t.color(color)
t.left(120)
t.fd(size)
t.left(120)
t.fd(size)
t.end_fill()
def draw_s(x,y,size,n):
if n == 0:
draw_tri(x,y,size)
return
draw_s(x,y,size/2,n-1)
draw_s(x+size/2,y,size/2,n-1)
draw_s(x+size/4,y+size*math.sqrt(3)/4,size/2,n-1)
draw_s(-300,-250,600,6)
t.update()
【问题讨论】:
-
你有什么问题?
-
如何制作三角形镶嵌
-
如果你看图像,你会看到有三个不同的方向。只需在三个方向上以预先指定的距离绘制直线。
标签: python geometry turtle-graphics tiling