python ——turtle画三角形

时间:2024-10-15 19:06:06

1、先画一条横线,再旋转120度,再画一条横线,再旋转120度,再画一条横线。这样三角形就画好了。算法就是这样。

python ——turtle画三角形

2、先导入turtle库。设置屏幕尺寸大小,如600×600. 创建turtle对象。

python ——turtle画三角形
python ——turtle画三角形
python ——turtle画三角形
python ——turtle画三角形

3、设定三角形一条边长度为200,笔颜色为红色。笔宽度为10.

python ——turtle画三角形

4、最关键的一步来了。画完一笔后,需转折120度,画下一边。然后再旋转120度,再画第三条边。

python ——turtle画三角形
python ——turtle画三角形
python ——turtle画三角形
python ——turtle画三角形
python ——turtle画三角形

5、改颜色试试。如改蓝色。pencolor()颜色改为英文blue。

python ——turtle画三角形
python ——turtle画三角形

6、改笔粗细。pensize()里的参数可改变。

python ——turtle画三角形
python ——turtle画三角形
© 手抄报圈