【发布时间】:2021-05-29 06:24:23
【问题描述】:
我在 youtube 上观看 Aperture 的视频:https://youtu.be/1w40fxsyraE?t=325
在提供的时间戳 (5:25) 处,他开始谈论创建分形的方法。我试图在 python 程序中复制它,但我得到了不同的输出。我不知道为什么我会得到这个输出,但数学似乎是正确的,所以我不知道要改变什么。谁能解释为什么我的输出看起来与视频中的不同?
import turtle as t
drawer = t.Turtle()
drawer.speed(1000)
# drawer.hideturtle()
drawer.penup()
#make dot A
dotAx = 125
dotAy = 150
drawer.goto(dotAx, dotAy)
drawer.dot(10, "red")
#
#make dot B
dotBx = 185
dotBy = 0
drawer.goto(dotBx, dotBy)
drawer.dot(10, "red")
#
#make dot C
dotCx = 0
dotCy = 0
drawer.goto(dotCx, dotCy)
drawer.dot(10, "red")
#
#make middle dot
dotPx = 100
dotPy = 75
drawer.goto(dotPx, dotPy)
drawer.dot(5,"yellow")
#
#draw dots v
x = 0
drawer.pendown()
while True:
if x == 0:
dotPx = (dotPx + dotAx)/2
dotPy = (dotPy + dotAy)/2
drawer.goto(dotPx, dotPy)
drawer.dot(5,"black")
print("A", dotPx, dotPy)
x+=1
if x == 1:
dotPx = (dotPx + dotBx)/2
dotPy = (dotPy + dotBy)/2
drawer.goto(dotPx, dotPy)
drawer.dot(5, "black")
print("B", dotPx, dotPy)
x+=1
if x == 2:
dotPx = (dotPx + dotCx)/2
dotPy = (dotPy + dotCy)/2
drawer.goto(dotPx, dotPy)
drawer.dot(5, "black")
print("C", dotPx, dotPy)
x = 0
【问题讨论】:
-
您能否以文本的形式描述您的问题,而不是参考某些视频。你得到的输出是什么?它与期望的输出有何不同?
标签: python math turtle-graphics fractals