turtle库学习笔记
一.定义:python的标准库之一,适用于新手入门编程,利用编程语言实现机器上的绘图。
二.自己的理解:利用简单的机器语言操控海龟画笔的上下左右移动,实现“画画功能”,涉及到角度、长度、前进后退、颜色等等。我们输入命令,机器去执行我们的想法。
三.海龟命令
绘图窗体 turtle.setup(xx,xx) 空间坐标体系turtle.goto(xx,xx),以窗口正中为原点(0,0),连续goto的使用可移动画笔 颜色使用turtle.colormode(mode)
角度坐标turtle.left/right(角度度数),此操作画笔是只改变方向不移动 海龟画笔直线向右/左turtle.fd/bk,海龟画笔曲线行走turtle.circle(半径长度,绘制角度),圆心默认在海龟左侧
画笔抬起turtle.penup,画笔落下turtle.pendown 抬起再移动时画笔不会在窗口上留下痕迹但会移动到指定位置
四.所学绘图
import turtle 等边三角形
turtle.setup(500,500)
for i in range(3):
turtle.fd(100)
turtle.right(120)
turtle.left(60)
turtle.fd(100)
for i in range(2):
turtle.right(120)
turtle.fd(200)
turtle.right(120)
turtle.fd(100)
turtle.setup(500,500) 五角星的绘制
turtle.fillcolor("red")
turtle.penup
turtle.bk(150)
turtle.pendown
turtle.begin_fill()
for i in range(5):
turtle.fd(300)
turtle.right(144)
turtle.end_fill()
turtle.done
原文:https://www.cnblogs.com/dongchidachi/p/12549467.html