标签:
python 版本:3.4.3
import 模块:turtle
使用turtle模块绘制多边图形,代码如下:
#-*- charset:utf-8 -*- import turtle #设置画笔笔迹宽度 turtle.pensize(3) #画三边形 turtle.color("red") turtle.penup() turtle.goto(-200,-50) turtle.pendown() turtle.circle(40, steps=3) #画四边形 turtle.color("green") turtle.penup() turtle.goto(-100,-50) turtle.pendown() turtle.circle(40, steps=4) #画五边形 turtle.color("blue") turtle.penup() turtle.goto(0,-50) turtle.pendown() turtle.circle(40, steps=5) #画六边形 turtle.color("yellow") turtle.penup() turtle.goto(100,-50) turtle.pendown() turtle.circle(40, steps=6) #画圆形 turtle.color("purple") turtle.penup() turtle.goto(200,-50) turtle.pendown() turtle.circle(40) turtle.done()
运行结果如图:
本程序关键是turtle.circle(radius, extent, steps)方法的参数设置
radius:指定所绘圆形的半径
extent:指定绘制多大角度的圆形
steps:指定圆形边数(3,4,5,6...)
标签:
原文地址:http://my.oschina.net/u/158964/blog/502335