-
python turtle库画图_《体验Python中turtle库画图》教学设计
2020-12-09 19:52:07《体验Python中turtle库画图》教学设计射阳县高级中学 张珊珊学情分析:学生从未接触过编程,因此通过画图来提高学生的学习积极性,而Python语言相较其他语言简单易学,程序里包含很多英语单词,而高中生的英语单词...《体验Python中turtle库画图》教学设计
射阳县高级中学 张珊珊
学情分析:
学生从未接触过编程,因此通过画图来提高学生的学习积极性,而Python语言相较其他语言简单易学,程序里包含很多英语单词,而高中生的英语单词词汇量比较丰富,稍加指点,很容易读懂程序代码,因此,海龟绘图很适合用来引导孩子学习编程。
教学目标:
1、知识与技能:了解turtle语句的书写规则,知道for循环语句的作用,以及变量的含义。
2、过程与方法:在“提出问题——老师讲解问题——自主实践解决问题——方法总结”的过程中,合理修改turtle语句,自主完成螺旋形绘图任务。
3、情感态度价值观:体验python中turtle语句的图形绘制魅力,激发同学编程的欲望。
教学重点:
1、掌握for循环语句的使用;
2、为图案添加色彩。
教学难点:
1、for循环语句的灵活使用
2、为图案添加多种颜色时,每一笔颜色的选择。
教学过程:
一、明确目标自主学
活动一:请同学一笔画出正方形,并说出正方形的特点。
设计意图:正方形的特点很好抓取,边长相等,四角均为90度。即便是人工画图,动笔之前也要做到心中有图,计算机画图亦是如此。
请一个同学扮演计算机,根据老师发布的指令移动位置,走出一个正方形。
设计意图:计算机作图必须接收人的指令,这些指令是以程序代码的方式呈现给计算机的。
Python就是这样一种程序设计语言,今天这节课跟大家一起体验利用Python里的turtle库画图。
介绍Python
Python是一种跨平台的。是一种面向对象的动态类型语言。汉语翻译过来是“蟒蛇”的意思,其logo标志也是两条蟒蛇馋在一起,为什么取名叫Python呢?因为它的创始人吉多,喜欢一个叫monty python 的喜剧团。
Python简单、易学、渲染速度快、代码免费、开放性好、越来越多被用于大型项目的开发,更重要的是它拥有很多标准库和第三方库,这就不需要所有的代码自己重新编写,我只要调用现成的代码就行。Turtle就是其中用于绘图的标准库。Turtle中文意思海龟,因此我们又叫海龟作图。
原理:想象一只海龟带着一只画笔在画布上爬行,通过控制海龟的爬行路线,我们可以绘制出令人惊奇的图片,比如:
设计意图:了解Python并感受turtle绘图的魅力,激发同学的创作欲望
我们可以画出这些酷炫的螺旋形吗?不急,只要你读懂了这些图案背后的代码,turtle画图就会变得轻而易举。
二、解决疑难互动学
活动二:认识第一个海龟程序——画正方形
设计意图:读懂Python程序代码,理解for循环语句,理解变量和各个参数,掌握代码书写格式,为后续画螺旋形做铺垫。
活动三:画螺旋形
思考:
1、螺旋形的边长应该怎么设置?
2、改变左转的角度,图形会有什么变化?
请同学到Python里将代码稍作改动,并保存运行,观察图案。
展示同学作品并评价。
设计意图:灵活设置参数,活学活用变量X,学生通过动手实践画出各种各样的螺旋形,不仅感官得到刺激,也大大满足内心的成就感。
活动四:彩色螺旋形
这些螺旋线的形状不错,但是,如果它们能够更多彩一些,是不是更酷呢?
1、添加颜色
import turtle
t = turtle.Pen()
t.speed(0)
t.pencolor(“yellow”)
for x in range(500):
t.forward(x)
t.left(100)
2、修改背景颜色
黄色中白色的背景上很难显示出来,让我们把背景颜色修改为黑色,来修正这个问题。
turtle.bgcolor(“black”)
添加这一行之后,图片更加漂亮,所有的颜色现在都处在黑色的背景之上。
import turtle
turtle.bgcolor(“black”)
t = turtle.Pen()
t.speed(0)
t.pencolor(“yellow”)
for x in range(500):
t.forward(x)
t.left(90)
3、添加多种颜色
如果想要让每一边都显示一种不同的颜色,我们该怎么办呢?这需要对程序做一些更多的修改。
首先,我们需要颜色名称的一个列表,而不是单个的颜色,因此,我们要创建一个名为colors的列表变量并且在列表中放置4种颜色,如下所示。
colors = [“red”, “yellow”, “blue”, “green”]
为了做到彩色螺旋线,我们需要将t.pencolor()函数移入到for循环下的一组指令之中,还需要告诉pencolor函数,我们想要使用列表中的哪一种颜色。
代码如下:
import turtle
t = turtle.Pen()
t.speed(0)
turtle.bgcolor("black")
colors = [“red”, “yellow”, “blue”, “green”]
for x in range(500):
t.pencolor(colors[x%4])
t.forward(x)
t.left(100)
至此,一个漂亮的螺旋形就诞生了。
同学作品展示并评价。
设计意图:丰富我们的作品,使其更出彩,更酷炫
课堂小结:
本节课通过分析正方形的Python代码,掌握了Python代码的书写规则,理解变量含义以及学会for循环的使用。在正方形代码基础上,通过改变forward的参数,旋转的角度并且增加循环次数就可以产生螺旋形,还学会了给图案增加色彩,使其更丰富,更酷炫。Turtle绘图库还有很多其他丰富的功能,期待跟同学们的下次体验。
-
python turtle库画图_python 用turtle库画图
2021-02-03 01:01:09"""Created on Tue Oct 30 21:46:05 2018@author: 木公子"""import turtle as tt.pensize(2)t.colormode(255)t.setup(800,600)t.speed(0)t.Turtle().screen.delay(0)#书t.pu()t.goto(-310,150)t.pd()t.seth(15) # 笔..."""
Created on Tue Oct 30 21:46:05 2018
@author: 木公子
"""
import turtle as t
t.pensize(2)
t.colormode(255)
t.setup(800,600)
t.speed(0)
t.Turtle().screen.delay(0)
#书
t.pu()
t.goto(-310,150)
t.pd()
t.seth(15) # 笔的角度为-30°
t.begin_fill() # 外形填充的开始标志
t.color("black",(153,153,101))
a=1.3
for i in range(90):
a-=0.005
t.fd(a)
t.rt(0.5)
t.seth(-90)
t.fd(40)
a=1.3
for i in range(70):
a-=0.005
t.fd(a)
t.lt(0.15)
t.seth(180)
a=1.3
for i in range(80):
if(i<=20):
a-=0.005
t.fd(a)
t.rt(0.5)
else:
a+=0.005
t.fd(a)
t.lt(0.5)
t.goto(-310,150)
t.end_fill()
#手
t.pu()
t.goto(-240,50)
t.pd()
t.seth(45)
t.begin_fill()
t.color("black",(250,209,189))
t.fd(28)
t.seth(0)
t.fd(10)
t.seth(-45)
t.fd(15)
t.seth(-60)
t.fd(13)
t.seth(180)
t.circle(15,86)
t.seth(105)
t.fd(24)
t.seth(45)
t.fd(8)
t.seth(-135)
t.fd(17)
t.pu()
t.goto(-240,50)
t.pd()
t.seth(-60)
t.circle(12,130)
t.end_fill()
#橘色衣服
t.pu()
t.goto(-209,37)
t.pd()
t.begin_fill()
t.color("black",(255,213,75))
t.seth(-90)
t.fd(15)
t.seth(-19)
t.fd(100)
t.seth(93)
a=1
for i in range(20):
t.fd(a)
t.rt(1)
t.seth(180)
t.circle(-20,90)
t.seth(160)
t.fd(70)
t.seth(-30)
t.circle(-40,30)
t.end_fill()
#头发
t.pu()
t.goto(-130,138)
t.pd()
t.begin_fill()
t.seth(67)
t.color("black","black")
t.circle(-136,105)
t.end_fill()
t.pu()
t.goto(-111,6)
t.pd()
t.begin_fill()
t.color("black",(252,158,8))
t.seth(-105)
for i in range(100):
t.fd(0.1)
t.lt(0.02)
t.seth(-80)
for i in range(200):
t.fd(0.1)
t.lt(0.02)
t.seth(0)
for i in range(50):
t.fd(1)
t.rt(0.05)
t.hideturtle()
t.end_fill()
t.pu()
t.goto(-133.5,28.5)
t.pd()
t.begin_fill()
t.color("black",(250,207,190))
t.seth(93)
t.circle(-20,110)
t.seth(170)
t.circle(20,30)
t.seth(125)
t.circle(-80,30)
t.seth(95)
for i in range(300):
t.fd(0.1)
t.rt(0.04)
t.circle(-65,60)
t.seth(80)
t.circle(-30,30)
t.seth(-85)
t.fd(13)
t.seth(45)
t.circle(-110,40)
t.seth(95)
t.fd(14)
t.seth(-52)
t.fd(18)
t.seth(0)
t.fd(30)
t.seth(0)
t.circle(-82,90)
for i in range(500):
t.fd(0.1)
t.rt(0.04)
for i in range(500):
t.fd(0.09)
t.lt(0.07)
t.seth(-89)
t.circle(-72,90)
for i in range(600):
t.fd(0.1)
t.rt(0.02)
t.circle(-104,47)
t.seth(160)
for i in range(200):
t.fd(0.1)
t.rt(0.07)
t.circle(-12,15)
t.hideturtle()
t.end_fill()
t.pu()
t.goto(-50,80)
t.pd()
t.begin_fill()
t.color("black",(255,255,255))
t.seth(0)
t.circle(20)
t.pu()
t.goto(20,80)
t.pd()
t.circle(20)
t.end_fill()
t.pu()
t.goto(-40,90)
t.pd()
t.begin_fill()
t.color("black",(0,0,0))
t.seth(0)
t.circle(10)
t.end_fill()
t.pu()
t.goto(10,90)
t.pd()
t.begin_fill()
t.color("black",(0,0,0))
t.seth(0)
t.circle(10)
t.end_fill()
t.pu()
t.goto(-35,30)
t.pd()
t.begin_fill()
t.color("black",(255,255,255))
t.seth(-60)
t.circle(35,120)
t.end_fill()
t.pu()
t.goto(540,-320)
t.pd()
t.write(‘木公子‘,font = (‘华文隶书‘ ,10 ,‘q‘,9,‘normal‘))
t.pendown()
#隐藏画笔箭头
t.hideturtle()#关闭turtlet.done()
-
使用python的turtle库画图撩妹
2020-05-25 11:16:33使用python的turtle库画图撩妹 话不多说,先上效果图,然后是代码 代码如下: import turtle turtle.penup() turtle.goto(-80,20) turtle.circle(50,30) turtle.pendown() turtle.circle(70,300) turtle.seth(-125...使用python的turtle库画图撩妹
话不多说,先上效果图,然后是代码
代码如下:import turtle turtle.penup() turtle.goto(-80,20) turtle.circle(50,30) turtle.pendown() turtle.circle(70,300) turtle.seth(-125) turtle.circle(300,20) turtle.penup() turtle.goto(-55,25)#右肩膀位置 turtle.pendown() turtle.seth(-67) turtle.fd(20) turtle.seth(-72) turtle.fd(20) turtle.seth(-76) turtle.fd(20) turtle.seth(-76) turtle.fd(40) turtle.penup() turtle.goto(-120,90)#左眉毛起点位置 turtle.pendown() turtle.seth(35) turtle.fd(20) turtle.penup() turtle.goto(-60,90)#右眉毛起点位置 turtle.pendown() turtle.seth(145) turtle.fd(20) turtle.penup() turtle.goto(-108,91)#左眼位置 turtle.pendown() turtle.width(3) turtle.circle(2,360) turtle.penup() turtle.goto(-72,91)#右眼位置 turtle.pendown() turtle.circle(2,360) turtle.width(1) turtle.penup() turtle.goto(-90,60)#嘴巴中心位置 #turtle.circle(10,20) turtle.pendown() turtle.circle(10,90) turtle.penup() turtle.goto(-90,60)#嘴巴中心位置 #turtle.circle(10,-20) turtle.pendown() turtle.circle(8,-120) turtle.penup() turtle.goto(-125,70)#左腮红位置 turtle.pendown() turtle.width(10) turtle.pencolor('hotpink') turtle.circle(5,360) turtle.penup() turtle.goto(-55,70) turtle.pendown() turtle.circle(5,360) turtle.penup() turtle.goto(-130,0)#左手起点 turtle.width(1) turtle.pencolor('black') turtle.pendown() turtle.seth(-90) turtle.fd(20) turtle.seth(-80) turtle.fd(20) turtle.circle(8,180) turtle.fd(40) turtle.penup() turtle.goto(-70,0)#右手起点 turtle.pendown() turtle.seth(-90) turtle.fd(20) turtle.seth(-100) turtle.fd(20) turtle.circle(8,180) turtle.fd(40) turtle.penup() turtle.goto(0,-30)#人物二起点 turtle.pendown() turtle.seth(85) turtle.fd(20) turtle.seth(80) turtle.fd(80) turtle.seth(120) turtle.fd(60) for i in range(4): turtle.seth(90-i*45) turtle.fd(10) turtle.seth(-55) turtle.fd(50) turtle.penup() turtle.circle(70,90) turtle.pendown() turtle.circle(70,270) turtle.penup() turtle.goto(140,80) turtle.pendown() turtle.seth(-45) turtle.fd(20) turtle.seth(-55) turtle.fd(40) for j in range(4): turtle.seth(-90-j*45) turtle.fd(10) turtle.fd(20) turtle.seth(120) turtle.fd(30) turtle.seth(-85) turtle.fd(90) turtle.penup() turtle.goto(55,155)#人物二左眉毛起点 turtle.pendown() turtle.seth(-30) turtle.fd(30) turtle.penup() turtle.fd(30) turtle.pendown() turtle.fd(30) turtle.penup() turtle.goto(59,138)#人物二做眼睛 turtle.pendown() turtle.width(5) turtle.circle(2,360) turtle.penup() turtle.goto(110,110) turtle.pendown() turtle.circle(2,360) turtle.width(1) turtle.penup() turtle.goto(68,95) turtle.pendown() for k in range(6): turtle.seth(-60+20*k) turtle.fd(5) turtle.width(10) turtle.penup() turtle.goto(56,110) turtle.pendown() turtle.pencolor('hotpink') turtle.circle(5,360) turtle.penup() turtle.goto(120,85) turtle.pendown() turtle.circle(5,360) turtle.pencolor('palegreen')#伞把颜色 turtle.penup() turtle.goto(-5,138) turtle.pendown() turtle.seth(120) turtle.fd(100) turtle.pencolor('skyblue')#伞颜色 turtle.seth(20) turtle.fd(80) turtle.seth(30) turtle.fd(50) turtle.seth(180) turtle.fd(50) turtle.seth(200) turtle.fd(150) turtle.seth(220) turtle.fd(70) turtle.seth(20) turtle.fd(130) turtle.done()
-
Python—turtle库画图神器
2017-10-16 16:22:03引入turtle库画图简直无敌,之前用过MATLAB的plot函数,感觉这个更强大,有海量的第三方库,简直完美有趣 1.彩色螺旋线的绘制 import turtle import time turtle.pensize(2) turtle.bgcolor("black") colors =...引入turtle库画图简直无敌,之前用过MATLAB的plot函数,感觉这个更强大,有海量的第三方库,简直完美有趣
1.彩色螺旋线的绘制
import turtle import time turtle.pensize(2) turtle.bgcolor("black") colors = ["red", "yellow",'purple','blue'] turtle.tracer(False) for x in range(400): turtle.forward(2*x) turtle.color(colors[x % 4]) turtle.left(91) turtle.tracer(True)
2.太阳花的绘制from turtle import * color('red', 'yellow') begin_fill() while True: forward(200) left(170) if abs(pos()) < 1: break end_fill() done()
3.五角星的绘制
from turtle import * fillcolor("red") begin_fill() while True: forward(200) right(144) if abs(pos()) < 1: break end_fill()
4.螺旋线绘制
import turtle import time turtle.speed("fastest") turtle.pensize(2) for x in range(100): turtle.forward(2*x) turtle.left(90) time.sleep(3)
仅供参考学习,转载请注明出处,谢谢 -
Python turtle库画图
2019-02-28 21:17:14第一次尝试用turtle画图,很艰难、不完美但十分具有纪念意义! 我这只小白会在Python的成长道路上越走越远的(ง •̀_•́)ง -
python turtle库画图_python中turtle库绘图
2020-12-09 19:52:08turtle(龟)绘图蟒蛇#form turtle import * 调用里面的库#import turtleimport turtle as tt.setup() #定义画布的大小setup(400,400,0,0)长宽,以及画布对于整个屏幕的定位t.penup() #提起画笔t.fd(-200) #移动箭头,... -
利用turtle库画图
2019-08-29 20:40:52turtle库是一个非常好的图形绘制工具,练习一段画图代码,代码如下。 from turtle import * def nose(x,y):#鼻子 penup()#提起笔 goto(x,y)#定位 pendown()#落笔,开始画 setheading(-30)#将乌龟的方向设置为to... -
使用turtle库画图
2018-12-20 22:01:00import turtle# 设置启动窗体的大小和位置,宽度高度,起始点的位置(后两者可选),不是必须的turtle.setup(650,350,200,200)# turtle.goto(100,100) 去某个地方,绝对坐标turtle.penup()turtle.fd(-250) # 正前方向... -
python 使用turtle库画图
2019-11-13 11:29:55Turtle库是python中较流行的函数库。 Turtle的基础知识表: 画布大小 canvas 我们展开用于绘画区域,可以设置大小、初始位置和背景颜色 screensize(canvwidth=None, canvheight=None, bg=None) ... -
python运用turtle库画图--关于疫情主题的图片
2020-06-09 22:12:25使用turtle库画出了这样一张关于疫情主题的图片,寄托我们美好的祝愿。 代码如下: import turtle as t import random def wheregoto(x,y): #x,y表示坐标 t.up() t.goto(x,y) t.down() t.speed(0) t.pensize(4... -
python使用turtle库画图
2018-10-21 12:32:53环境:python3.6中自带turtle库 代码: import turtle turtle.pensize(2)#画线宽度 turtle.bgcolor("black")#设置背景颜色 colors=["red","yellow","blue","purple... -
Python——利用turtle库画图
2020-07-15 17:47:27turtle库的简单使用 import turtle #左转45度 turtle.left(45) #向后50 turtle.bk(50) #右转135度 turtle.right(135) #向前50 turtle.fd(50) turtle.left(135) turtle.fd(150) #单击退出,没有这段条指令就直接退出... -
【Python】使用Turtle库画图
2020-03-24 21:02:53【Python】使用Turtle库画图绘图窗体布局基本语句小案例 在Python中一般是引用turtle这个函数库来画图,其画图方法就好像一只海龟在白纸上爬,爬行轨迹就是所画的图形。 绘图窗体布局 turtle绘图窗体,就是Python... -
python 用turtle库画图
2018-11-13 23:31:00t.Turtle().screen.delay(0) 14 # 书 15 t.pu() 16 t.goto(-310,150 ) 17 t.pd() 18 t.seth(15) # 笔的角度为-30° 19 t.begin_fill() # 外形填充的开始标志 20 t.color( " black " ... -
使用python的turtle库画图
2017-10-10 23:12:55引、想要使用python作画吗? 那就用turtle库吧,使用它...一、使用方法:1、引入方式(两种):import turtle #导入turtle库,使用时通过turtle.function调用 from turtle import * #导入turtle库中所有方法,直接通过f -
python turtle库画图案-Python基础图形绘制库——turtle
2020-11-01 13:18:25介绍turtle库也叫海龟库,是turtle绘图体系的Python实现。turtle库是Python语言的标准库之一,是入门级的图形绘制函数库。turtle绘图体系:也叫海龟绘图系统,它是在1969年诞生,主要用于程序设计入门的一种绘图方式... -
python turtle库画图案-python中的turtle库绘制图形
2020-11-01 12:59:411. 前奏:在用turtle绘制图形时,需要安装对应python的解释器以及IDE,我安装的是pycharm,在安装完pycharm后,在pycharm安装相应库的模块,绘图可以引入turtle模块,想要进行运算可以引入numpy模块。需要注意: 在... -
python turtle库画图案-Python如何使用turtle库绘制图形
2020-11-01 12:59:411. 前奏:在用turtle绘制图形时,需要安装对应python的解释器以及IDE,我安装的是pycharm,在安装完pycharm后,在pycharm安装相应库的模块,绘图可以引入turtle模块,想要进行运算可以引入numpy模块。需要注意: 在...