网络编程
位置:首页>> 网络编程>> Python编程>> python turtle库画一个方格和圆实例

python turtle库画一个方格和圆实例

作者:V领happy  发布时间:2021-09-25 14:06:10 

标签:python,turtle,方格,圆

使用python的turtle库画一个方格和圆

打开python编译器,导入turtle库

from turtle import *

python turtle库画一个方格和圆实例

首先画一个距离为100的横线

forward(100)

python turtle库画一个方格和圆实例

顺时针旋转90度,前进100

python turtle库画一个方格和圆实例

在通过两次的旋转和平移得到方格,使用for循环重复两次

python turtle库画一个方格和圆实例

抬起笔,直接到方格的中间,也就是(50,0)坐标


penup()

goto(50,0)

python turtle库画一个方格和圆实例

开始画半径为50的圆,放下笔


pendown()

circle(50)


python turtle库画一个方格和圆实例

在圆的中心画个圆心点


goto(50,50)

dot()

python turtle库画一个方格和圆实例

最后隐藏画笔,完成绘画

python turtle库画一个方格和圆实例

总结:

来源:https://jingyan.baidu.com/article/bea41d43fadb36b4c41be65c.html

0
投稿

猜你喜欢

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