Pre-class learning python 01 turtle

Python examples:

 

 

turtle library introduced import turtle # 
t = turtle.Pen () # provided a brush
t.shape ( 'turtle') # turtle shape to the brush
t.up () # lifting brush
t.fd (-250) # lift since the brush is moved without leaving lines
t.down () # brush down
t.pensize (25) # set brush thickness
t.seth (-40) # absolute angle becomes -40
t.color ( 'Purple') # brush color to violet
for i in range (4): # circle drawn by an array of distorted body
t.circle (40,80) # radius 40, the angle of the circular portion 80
t.circle (-40,80)
T .left (40) # 40 left rotation direction doing, the relative angle
t.fd (40) # forward 40
t.circle (20, 180) # circle, turn
t.fd (30)
turtle.mainloop () # holding cycle the window does not disappear

colorful snake modified example ...

 

 

 

color_list = ['red','pink','green','blue','yellow']

for i in color_list:
t.color(i)
t.circle(40, 80)
t.circle(-40, 80)

t.color('black')
t.left(40)
t.fd(40)
t.circle(20,180)
t.fd(30)
turtle.mainloop()

作业:

 

 

 

import turtle
t=turtle.Pen()
t.shape('turtle') #设置画笔为海龟
turtle.setup(800,800,100,100) #turtle.setup(width,height,startx,starty) 前两参数窗体大小,后两参数窗体左上角所在显示器位置
t.speed(15) #画笔速度

t.fillcolor('yellow') #脸,设置填充色为黄色
t.color('yellow') #设定画笔颜色为黄色
t.pensize(10) #设置画笔粗细
t.begin_fill() #开始填充颜色
t.circle(150,360) #画圆
t.end_fill() #结束填充颜色

t.up() #嘴,抬起画笔
t.fd(140) #画笔前进140
t.left(90) #向左旋转90度
t.fd(140)
t.down() #落下画笔
t.color('red')
t.pensize(5)
t.circle(138,-180)

t.up() #左眼
t.goto(-20,180) #画笔移动到指定坐标
t.down()
t.color('white')
t.pensize(25)
t.left(70) #相对角度向左旋转70°
for i in range(10): #调整眼睛弧度
t.fd(-10)
t.left(5)
t.up() #左眼珠
t.goto(-110,170)
t.down()
t.fillcolor('black')
t.color('black')
t.pensize(10)
t.begin_fill()
t.circle(10,360)
t.end_fill()

t.up() #右眼
t.goto(20,180)
t.down()
t.color('white')
t.pensize(25)
t.seth(20) #绝对角度为20°
for i in range(10):
t.fd(10)
t.right(5)
t.up() #右眼珠
t.goto(20,170)
t.down()
t.fillcolor('black')
t.color('black')
t.pensize(10)
t.begin_fill()
t.circle(10,360)
t.end_fill()

t.up() #左眉毛
t.goto(-20,240)
t.down()
t.color('black')
t.pensize(2)
t.seth(130) #绝对角度为130°
for i in range(10): #调整眉毛弧度,粗细
t.fd(6)
t.left(7)
t.pensize(i)
for i in range(10):
t.fd(6)
t.left(7)
t.pensize(10-i)

t.up() #右眉毛
t.goto(20,240)
t.down()
t.color('black')
t.pensize(2)
t.seth(50) #绝对角度为50°
for i in range(10):
t.fd(6)
t.right(7)
t.pensize(i)
for i in range(10):
t.fd(6)
t.right(7)
t.pensize(10-i)
turtle.mainloop() #保持循环,保留窗口

Guess you like

Origin www.cnblogs.com/ludingchao/p/11720346.html