python turtle 八角形的制作 在python中turtle绘制正七边形

Python\u753b\u516b\u89d2\u661f\u7684\u7a0b\u5e8f

\u591a\u8fb9\u5f62\u7684\u753b\u6cd5
def ployon(num, distance):
# bob.color('blue', 'red')
bob.color("red", "yellow")
for i in range(num):
bob.fd(distance)
bob.lt(360 / num)
time.sleep(1)
bob.end_fill()
bob.filling()
time.sleep(3)
bob.reset()


# ployon(3, 100)
# ployon(4, 100)
# ployon(5, 100)
# ployon(6, 100)
# ployon(7, 100)
# ployon(8, 100)


# # \u4e94\u89d2\u661f\u7684\u753b\u6cd5
# bob.color("red", "yellow")
# for i in range(5):
# bob.fd(200)
# bob.right(180 - 36)
# time.sleep(0.5)
# bob.end_fill()
#
# bob.reset()
#
# # \u516b\u89d2\u661f
# bob.color("red", "yellow")
# for i in range(8):
# bob.fd(200)
# bob.right(180 - 45)
# time.sleep(0.5)
# time.sleep(10)
#
# bob.reset()


# \u516d\u89d2\u661f
# bob.color("red", "yellow")
# for i in range(3):
# bob.fd(200)
# bob.right(180 - 60)
# time.sleep(0.5)
#
# bob.up()
# bob.lt(30)
# bob.fd(200 / math.sqrt(3))
# bob.rt(90)
# bob.down()
#
# for i in range(3):
# bob.fd(200)
# bob.right(180 - 60)
# time.sleep(0.5)
# time.sleep(2)
#
# bob.reset()




# \u8ff7\u5bab\u7684\u753b\u6cd5
def squareSpiral(ra):
bob.pencolor("green")
for x in range(100):
bob.forward(x)
bob.left(ra)
time.sleep(3)
bob.reset()




def circleSpiral(ra):
bob.pencolor("green")
for x in range(100):
bob.circle(x)
bob.left(ra)
time.sleep(3)
bob.reset()


# \u8ff7\u5bab
# squareSpiral(90)
# # \u5927\u98ce\u8f66
# squareSpiral(91)
# # \u6f29\u6da1
# circleSpiral(90)


# \u82b1\u6735
# circleSpiral(60)


def circleSpiral2(ra):
bob.pencolor("green")
a = 0;
n = 360 / ra
while(a + 1 <= n):
bob.circle(50)
bob.left(ra)
a = a + 1
time.sleep(3)
bob.reset()
\u9605\u8bfb\u5168\u6587

\u2460 \u4ee5\u5b9a\u957fR\u4e3a\u534a\u5f84\u4f5c\u5706\uff0c\u5e76\u8fc7\u5706\u5fc3O\u4f5c\u4e92\u76f8\u5782\u76f4\u7684\u7eb5\u6a2a\u4e24\u6761\u76f4\u5f84MN\u3001HP. \u2461 \u8fc7N\u70b9\u4efb\u4f5c\u4e00\u5c04\u7ebfNS\uff0c\u7528\u5706\u89c4\u53d6\u4e03\u7b49\u5206\uff0c\u628a\u7aef\u70b9T\u4e0eM\u8fde\u7ed3\u8d77\u6765\uff0c\u7136\u540e\u8fc7NT\u4e0a\u7684\u5404\u70b9\u63a8\u51faMT\u7684\u5e73\u884c\u7ebf\uff0c\u628aMN\u4e03\u7b49\u5206. \u2462\u4ee5 M\u4e3a\u5706\u5fc3\uff0cMN\u4e3a\u534a\u5f84\u753b\u5f27\uff0c\u548cPH\u7684\u5ef6\u957f\u7ebf\u76f8\u4ea4\u4e8eK\u70b9\uff0c\u4eceK\u5411MN\u4e0a\u5404\u5206\u70b9\u4e2d\u7684\u5076\u6570\u70b9\u6216\u5947\u6570\u70b9\uff08\u56fe\u4e2d\u662f 1\u30013\u30015\u30017\u5404\u70b9\uff09\u5f15\u5c04\u7ebf\uff0c\u4e0e\u4ea4\u4e8eA\u3001B\u3001C\u3001M.\u518d\u5206\u522b\u4ee5 AB\u3001BC\u3001CM\u4e3a\u8fb9\u957f\uff0c\u5728\u5706\u5468\u4e0a\u4eceA\u70b9\uff08\u6216M\u70b9\uff09\u5f00\u59cb\u5404\u622a\u4e00\u6b21\uff0c\u5f97\u5230\u5176\u4ed6\u4e09\u70b9\uff0c\u628a\u8fd9\u4e9b\u70b9\u4f9d\u6b21\u8fde\u7ed3\u8d77\u6765\uff0c\u5373\u5f97\u8fd1\u4f3c\u7684\u6b63\u4e03\u8fb9\u5f62. \u8fd9\u79cd\u753b\u6cd5\u9002\u7528\u753b\u5706\u5185\u63a5\u4efb\u610f\u6b63\u591a\u8fb9\u5f62.

from turtle import *

fillcolor('pink')
begin_fill()
for i in range(8):
    forward(100)
    right(45)
end_fill()

exitonclick()

假设每一条边长长为100

画八边形需要在前进100后向右转45度,重复(也就是循环)8次即可



扩展阅读:python turtle graphics ... python turtle 用法 ... python turtle fd ... python网站 ... python for beginners ... turtle seth 90 ... turtle write ... python turtle画图代码 ... pythonturtle画小白兔 ...

本站交流只代表网友个人观点,与本站立场无关
欢迎反馈与建议,请联系电邮
2024© 车视网