网络编程
位置:首页>> 网络编程>> Python编程>> Python turtle库绘制菱形的3种方式小结

Python turtle库绘制菱形的3种方式小结

作者:toto+  发布时间:2022-04-10 14:08:19 

标签:Python,turtle,菱形

绘制一个菱形四边形,边长为 200 像素。方法1和2绘制了内角为60和120度的菱形,方法3绘制了内角为90度的菱形。

方法1‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‮‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‫‬‮‬‪‬‪‬‪‬‪‮‬‫


import turtle as t
ls = [30,-30,-150,150]#菱形各边的画笔绝对角度列表
for i in range(4):
 t.seth(ls[i])  #画笔转向相应绝对角度
 t.forward(200)
t.done()

方法2


import turtle as t
t.right(-45)  #起始顶点绝对角度设为正30度
for i in range(4):  #画4边,转向4次
 t.fd(200)  
 degree = 60*(1+i%2)  #其他3顶点右转角度分别为60、120、60度
 t.right(degree)
t.done()

效果图如下:

Python turtle库绘制菱形的3种方式小结

方法3


import turtle as t
t.circle(200,steps=4)  #circle(r,steps)函数画半径为r圆的内切steps边形

效果图如下:

Python turtle库绘制菱形的3种方式小结

来源:https://blog.csdn.net/lzqg1990/article/details/88917549

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com