Turtle绘制小汽车

1、效果图:

2、完整代码

import turtle

t = turtle.Turtle() #创建一个新的画布对象

t.penup()
t.goto(0,80)
t.pendown()

t.fillcolor("red")
t.begin_fill()
t.lt(180)     
t.fd(60)
t.lt(45)   
t.fd(113)
t.rt(45)   
t.fd(80)
t.lt(90)   
t.fd(80)
t.lt(90)
t.fd(400)
t.lt(90)
t.fd(80)
t.lt(90)
t.fd(80)
t.rt(90)
t.fd(80)
t.lt(90)
t.fd(100)
t.end_fill()


t.penup()
t.goto(-140,-80)
t.pendown()

t.fillcolor("black")
t.begin_fill()
t.circle(40)
t.end_fill()

t.penup()
t.goto(80,-80)
t.pendown()

t.fillcolor("black")
t.begin_fill()
t.circle(40)
t.end_fill()

turtle.exitonclick()

3、海龟绘图常用功能

t.pensize(5)      #设置画笔的大小,Python中所有表示长度的单位都是些像素
t.pencolor(“red”)  #设置画笔的颜色,这里设置为红色,也可以是rgb三元组
t.speed(speed):#设置画笔移动速度,画笔绘制的速度范围[0,10]整数,数字越大越快。
t.forward(像素)  #向前运动,可缩写:t.fd(像素)
t.backward(像素)  #向后运动,可缩写:t.bd(像素)
t.lift(像素)  #向左运动,可缩写:t.lt(像素)
t.right(像素)  #向右运动,可缩写:t.rt(像素)
t.goto(像素x,像素y) #将画笔移动到某个点
turtle.pendown() #放下画笔,移动海龟时绘制线条。
turtle.penup() #提起画笔,移动海龟但不绘制线条。

4、玫瑰花(转载)

from turtle import *
import time

setup(1000,800,0,0)
speed(0)
penup()
seth(90)
fd(340)
seth(0)
pendown()

speed(5)
begin_fill()
fillcolor('red')
circle(50,30)

for i in range(10):
    fd(1)
    left(10)

circle(40,40)

for i in range(6):
    fd(1)
    left(3)

circle(80,40)

for i in range(20):
    fd(0.5)
    left(5)

circle(80,45)

for i in range(10):
    fd(2)
    left(1)

circle(80,25)

for i in range(20):
    fd(1)
    left(4)

circle(50,50)

time.sleep(0.1)

circle(120,55)

speed(0)

seth(-90)
fd(70)

right(150)
fd(20)

left(140)
circle(140,90)

left(30)
circle(160,100)

left(130)
fd(25)

penup()
right(150)
circle(40,80)
pendown()

left(115)
fd(60)

penup()
left(180)
fd(60)
pendown()

end_fill()

right(120)
circle(-50,50)
circle(-20,90)

speed(1)
fd(75)

speed(0)
circle(90,110)

penup()
left(162)
fd(185)
left(170)
pendown()
circle(200,10)
circle(100,40)
circle(-52,115)
left(20)
circle(100,20)
circle(300,20)
speed(1)
fd(250)

penup()
speed(0)
left(180)
fd(250)
circle(-300,7)
right(80)
circle(200,5)
pendown()

left(60)
begin_fill()
fillcolor('green')
circle(-80,100)
right(90)
fd(10)
left(20)
circle(-63,127)
end_fill()

penup()
left(50)
fd(20)
left(180)

pendown()
circle(200,25)

penup()
right(150)

fd(180)

right(40)
pendown()
begin_fill()
fillcolor('green')
circle(-100,80)
right(150)
fd(10)
left(60)
circle(-80,98)
end_fill()

penup()
left(60)
fd(13)
left(180)

pendown()
speed(1)
circle(-200,23)

exitonclick()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值