画饼图
importturtle
t=turtle.Pen()for i in range(5):
t.penup()
t.goto(0,-i*30)
t.pendown()
t.circle(i*30+30)
turtle.done()
画棋盘
importturtle
t=turtle.Pen()
widthall= 200width= 20num= widthall // 20 * 2 + 1t.speed(10)for r inrange(num):
t.penup()
t.goto(-widthall, widthall - width *r)
t.pendown()
t.goto(widthall, widthall- width *r)for c inrange(num):
t.penup()
t.goto(-widthall + width *c, widthall)
t.pendown()
t.goto(-widthall + width * c, -widthall)
turtle.done()
海龟绘图
绘制简单的五角星。
导入turtle模块
默认情况下,海龟的开始位置在窗口的中间,朝向右下方,笔是向下的。
然后,控制海龟进行多次转弯,画出线段。
星形的中心是正五边形,正五边形的每个内角为108°。
五个等腰山叫醒连接在五边形的外部。
因为五边形的一侧形成三角形延伸,每个三角形的底角为72°(补角:180°-108°)
等腰三角形的两个底角度数相同,加起来是144°。所以第三个角必须是36°。
为了实现急转弯,在星形的每个顶点需要转144°(即180°-36°)。
因此在每个顶点,有turtle.right(144)。
importturtle
t=turtle.Pen()
t.forward(100)
t.right(144)
t.forward(100)
t.right(144)
t.forward(100)
t.right(144)
t.forward(100)
t.right(144)
t.forward(100)
turtle.done()
谢谢