python使用turtle库绘制图形简单示例

1.同切圆的绘制

import turtle          # 引用turtle库
turtle.pensize(2)      # 设置画笔宽度为2像素
turtle.circle(10)      #绘制半径为10像素的圆
turtle.circle(40)      #绘制半径为40像素的圆
turtle.circle(80)      #绘制半径为80像素的圆
turtle.circle(160)      #绘制半径为160像素的圆

结果如下图所示
python使用turtle库绘制图形简单示例_第1张图片2.五角星的绘制

from turtle import *           # 引用turtle库
fillcolor("red")               # 设置填充颜色为红色
begin_fill()                   # 开始绘制
while True:
    forward(200)
    right(144)
    if abs(pos()) < 1:
        break
end_fill()

结果如图
python使用turtle库绘制图形简单示例_第2张图片3.太阳花的绘制

from turtle import *             # 引用turtle库
color('red','yellow')            # 设置画笔和填充颜色
begin_fill()
while True:
    forward(200)
    left(170)
    if abs(pos()) < 1:
        break
end_fill()
done()

结果如图
python使用turtle库绘制图形简单示例_第3张图片

你可能感兴趣的:(python,python)