认识turtle库(内置的海龟库)
python官网地址: https://docs.python.org/zh-cn/3/library/turtle.html
海龟绘图很适合用来学习python编程。 最初来自于 Wally Feurzeig, Seymour Papert 和 Cynthia Solomon 于 1967 年所创造的 Logo 编程语言。
请想象绘图区有一只机器海龟,起始位置在 x-y 平面的 (0, 0) 点。先执行 import turtle,再执行 turtle.forward(15),它将(在屏幕上)朝所面对的 x 轴正方向前进 15 像素,随着它的移动画出一条线段。再执行 turtle.right(25),它将原地右转 25 度
1.1turtle的绘制窗体
turtle.screensize(800,800, "green")
窗口大小和位置不会变,变的只是画布大小,画布大于窗口,会显示滚动条
1.2turtle的坐标系



2.标准库的导入和引用
-库的分类
第三库的地址 https://pypi.org/project/pip/
image.png
- 标准库
https://docs.python.org/zh-cn/3/library/
image.png
image.png
image.png
- 第三方库
- 自定义模块
python模块导入






3.1开始turtle
3.2如何画圆

画圆
import turtle #导入标准库
turtle.circle(100) #画圆
turtle.done()#用来停止画笔绘制,但绘图窗体不关闭

画三角形
import turtle
turtle.circle(50,360,3)
turtle.done()

3.3添加颜色


import turtle #导入内置函数
turtle.color('pink',)
turtle.circle(100) #画圆
turtle.done()#用来停止画笔绘制,但绘图窗体不关闭
3.4如何实现8字

import turtle #模块的导入
turtle.color('cyan') #颜色
turtle.circle(50) #回顾上面代码
turtle.color('olive')
turtle.circle(-60)
turtle.done()
3.5 实现套圈

import turtle
turtle.pensize(2) #设置笔的大小
turtle.pencolor('pink') #设置笔的颜色
turtle.circle(100)
turtle.pencolor('olive')
turtle.circle(80)
turtle.pencolor('yellow')
turtle.circle(60)
turtle.done()
自己学习预习
from turtle import *
color('red','pink')#画笔色red,背景色pink
begin_fill()
left(135)#左转135°
fd(100)#前进100像素
right(180)#画笔掉头
#重点理解circle()
#以垂直于当前方向的正左侧30像素处为圆心,圆心与当前位置的连线为半径,
#-180°方向(相对当前方向)画弧,画笔方向不变
#如果是180°是画笔正向前进画弧,-180°时画笔是倒退着画弧的
circle(30,-180)
backward(35)#由于此时画笔方向约为绝对方向的135°,需倒退画线
right(90)
forward(35)
circle(-30,180)
fd(100)
end_fill()
hideturtle()
done()

蓝桥杯真题

网友评论