Python绘制同切圆和同心圆

作者:烟中隐约闪现 | 创建时间: 2023-06-13
本文利用Python的turtle库,介绍了绘制同切圆和同心圆的方法。其中绘制同心圆用到了for循环。...
Python绘制同切圆和同心圆

操作方法

第一,首先启动Python自带的集成开发环境IDLE。点击开始-->Python 3.7-->IDLE.

第二,在IDLE中,点击File-->New File,新建一个脚本文件,然后输入如下代码,绘制同切圆。 # 2018123绘制同切圆 import turtle  # 导入turtle库 turtle.setup(500,500,100,100)  # 设置窗口宽高和距离左上距离 turtle.pensize(3)  # 设置画笔粗细 turtle.pencolor('red')  # 设置画笔颜色 turtle.right(90)  # 设置笔尖右旋90度 turtle.penup()  # 设置笔尖朝上 turtle.fd(100)  # 设置前进100像素 turtle.pendown()  # 设置笔尖朝下 turtle.seth(0)  # 设置(前进)方向归零 turtle.circle(50)  # 画半径50像素的圆 turtle.circle(100)  # 画半径100像素的圆 turtle.circle(150)  # 画半径150像素的圆 turtle.hideturtle()  # 设置隐藏笔尖

第三,保存上述脚本(保存快捷键Ctrl+S),然后运行该脚本(运行快捷键F5)。得到如下图形。

第四,再次点击File-->New File,再新建一个脚本文件,然后输入如下代码,绘制同心圆。 # 20181223绘制同心圆 import turtle from turtle import *  # 导入turtle库中的所有函数 setup(500,500,100,100) pensize(5) pencolor('red') shape('turtle')  # 设置笔尖类型为海龟turtle speed(0.7)  # 设置绘制速度 circle(15) for i in range(4): right(90) penup() fd(15) seth(0) pendown() circle(30+i*15) left(-90) penup() fd(50) right(90) fd(150) right(90) fd(150)

第五,保存和运行第四步中的脚本,得到如下同心圆的图形。

点击展开全文

更多推荐