欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Python动态画图实例代码(Turtle Graphics)

程序员文章站 2022-06-22 17:10:29
1. 穿雨鞋的小鸭from turtle import * #扁嘴pensize(2) pu()goto(-100,100)#上嘴最高顶点seth(-50)pd()color('#6C3100','#FADD77')begin_fill()fd(16)vertex_right = pos()#嘴最右顶点rt(50)fd(12)vertex_down = pos()#下嘴最低顶点rt(80)fd(30)circle(-3,200)vertex_left = pos(...

1. 穿雨鞋的小黄鸭

from turtle import *
 
#扁嘴
pensize(2)
 
pu()
goto(-100,100)#上嘴最高顶点
seth(-50)
pd()
color('#6C3100','#FADD77')
begin_fill()
fd(16)
vertex_right = pos()#嘴最右顶点
rt(50)
fd(12)
vertex_down = pos()#下嘴最低顶点
rt(80)
fd(30)
circle(-3,200)
vertex_left = pos()#嘴最左顶点
goto(-100,100)
end_fill()
goto(vertex_left)#回到最左顶点
circle(-3,-200)#扁嘴
goto(vertex_right)
    
#身体
#头颈背尾曲线
color('#B6A88E')
pu()
goto(-100,100)
pd()
 
seth(80)
circle(-36,160)
fd(25)
circle(115,20)
circle(60,55)
circle(-200,20)
circle(110,20)
color('#7D6A4C')
circle(40,40)
color('#B6A88E')
seth(-100)
circle(-180,30)
circle(-20,50)
 
#右鸭腿
circle(20,70)
color('#736856')
circle(-12,120)
leg_pos1 = pos()#定位左腿位置
fd(25)
 
#前胸肚曲线
pu()
goto(vertex_down)
pd()
seth(-10)
color('#B9AD9D')
circle(-40,50)
circle(-80,48)
color('#736856')
circle(250,5)
circle(50,75)
color('#B9AD9D')
circle(220,28)
 
#左鸭腿
pu()
seth(175)
fd(40)
pd()
seth(-120)
fd(8)
circle(-10,120)
leg_pos2 = pos()#定位右腿位置
fd(15)
 
#眼睛
color('black')
#左眼
pu()
goto(vertex_down - (1,-29))
pd()
dot(4,'black')#相比circle(),不需要再额外填充颜色
#右眼
pu()
goto(vertex_down + (23,20))
pd()
dot(4,'black')
 
 
#翅膀
color('#BCB2A6')
pu()
goto(vertex_down - (-75,130))
seth(130)
pd()
circle(-25,130)
circle(-100,30)
fd(85)
point = pos()
rt(137)
fd(52)
circle(-100,58)
 
pu()
goto(point)
lt(30)
pd()
fd(60)
 
pu()
goto(point)
pd()
lt(10)
fd(70)
 
 
#腿部
#左腿
def leg(pos0):#鸭腿绘制函数
    pensize(8)
    color('#ECC578')
    pu()
    goto(pos0)
    seth(0)
    fd(7)
    seth(-90)
    fd(8.5)
    pd()
    fd(20)#腿长
 
leg(leg_pos1)
leg(leg_pos2)
 
#小红靴——函数
def boot(pos0):
    pensize(2)
    color('#B4070B','#FBA06B')
    pu()
    goto(pos0)#靴子右上顶点
    pd()
    begin_fill()
    seth(140)
    circle(25,80)
    seth(-80)
    fd(35)#fd(30)左侧线条
 
    circle(-2,60)#靴低
    fd(20)
    circle(4,180)    
    seth(5)
    fd(30)
    circle(2,60)
    
    goto(pos0)#右侧线条
    end_fill()
    
boot(leg_pos1-(-20,30))
boot(leg_pos2-(-20,30)) 
    
 
#小雨滴
color('#77DDFF','#D8E8E5')
fd_ls = [200,140,250,240,230,220,180,250]
lt_ls = [30,60,60,100,125,170,200,330]
for i in range(8):
    pu()
    home()    
    lt(lt_ls[i])
    fd(fd_ls[i])
 
    pd()
    seth(-78)
    fd(15)
    begin_fill()
    circle(-3,200)
    end_fill()
    fd(15)
 
#文字
pu()
goto(vertex_left)
seth(180)
fd(150)
seth(-90)
fd(300)
color('black')
write('code by totoup',font=("Arial",15,"normal"))
    
hideturtle()
done() 

2.告白(一)

 import turtle
import time
 
 
# 清屏函数
def clear_all():
    turtle.penup()
    turtle.goto(0, 0)
    turtle.color('white')
    turtle.pensize(800)
    turtle.pendown()
    turtle.setheading(0)
    turtle.fd(300)
    turtle.bk(600)
 
 
# 重定位海龟的位置
def go_to(x, y, state):
    turtle.pendown() if state else turtle.penup()
    turtle.goto(x, y)
 
 
# 画线
# state为真时海龟回到原点,为假时不回到原来的出发点
def draw_line(length, angle, state):
    turtle.pensize(1)
    turtle.pendown()
    turtle.setheading(angle)
    turtle.fd(length)
    turtle.bk(length) if state else turtle.penup()
    turtle.penup()
 
 
# 画箭羽
def draw_feather(size):
    angle = 30                          # 箭的倾角
    feather_num = size//6               # 羽毛的数量
    feather_length = size // 3          # 羽毛的长度
    feather_gap = size//10              # 羽毛的间隔
    for i in range(feather_num):
        draw_line(feather_gap, angle+180, False)            # 箭柄,不折返
        draw_line(feather_length, angle + 145, True)        # 羽翼,要折返
    draw_line(feather_length, angle + 145, False)
    draw_line(feather_num*feather_gap, angle, False)
    draw_line(feather_length, angle + 145 + 180, False)
    for i in range(feather_num):
        draw_line(feather_gap, angle+180, False)            # 箭柄,不折返
        draw_line(feather_length, angle - 145, True)        # 羽翼,要折返
    draw_line(feather_length, angle - 145, False)
    draw_line(feather_num*feather_gap, angle, False)
    draw_line(feather_length, angle - 145 + 180, False)
 
 
# 画爱心
def draw_heart(size):
    turtle.color('red', 'pink')
    turtle.pensize(2)
    turtle.pendown()
    turtle.setheading(150)
    turtle.begin_fill()
    turtle.fd(size)
    turtle.circle(size * -3.745, 45)
    turtle.circle(size * -1.431, 165)
    turtle.left(120)
    turtle.circle(size * -1.431, 165)
    turtle.circle(size * -3.745, 45)
    turtle.fd(size)
    turtle.end_fill()
 
 
# 画箭
def draw_arrow(size):
    angle = 30
    turtle.color('black')
    draw_feather(size)
    turtle.pensize(4)
    turtle.setheading(angle)
    turtle.pendown()
    turtle.fd(size*2)
 
 
# 一箭穿心
# 箭的头没有画出来,而是用海龟来代替
def arrow_heart(x, y, size):
    go_to(x, y, False)
    draw_heart(size*1.15)
    turtle.setheading(-150)
    turtle.penup()
    turtle.fd(size*2.2)
    draw_heart(size)
    turtle.penup()
    turtle.setheading(150)
    turtle.fd(size * 2.2)
    draw_arrow(size)
 
 
# 画出发射爱心的小人
def draw_people(x, y):
    turtle.penup()
    turtle.goto(x, y)
    turtle.pendown()
    turtle.pensize(2)
    turtle.color('black')
    turtle.setheading(0)
    turtle.circle(60, 360)
    turtle.penup()
    turtle.setheading(90)
    turtle.fd(75)
    turtle.setheading(180)
    turtle.fd(20)
    turtle.pensize(4)
    turtle.pendown()
    turtle.circle(2, 360)
    turtle.setheading(0)
    turtle.penup()
    turtle.fd(40)
    turtle.pensize(4)
    turtle.pendown()
    turtle.circle(-2, 360)
    turtle.penup()
    turtle.goto(x, y)
    turtle.setheading(-90)
    turtle.pendown()
    turtle.fd(20)
    turtle.setheading(0)
    turtle.fd(35)
    turtle.setheading(60)
    turtle.fd(10)
    turtle.penup()
    turtle.goto(x, y)
    turtle.setheading(-90)
    turtle.pendown()
    turtle.fd(40)
    turtle.setheading(0)
    turtle.fd(35)
    turtle.setheading(-60)
    turtle.fd(10)
    turtle.penup()
    turtle.goto(x, y)
    turtle.setheading(-90)
    turtle.pendown()
    turtle.fd(60)
    turtle.setheading(-135)
    turtle.fd(60)
    turtle.bk(60)
    turtle.setheading(-45)
    turtle.fd(30)
    turtle.setheading(-135)
    turtle.fd(35)
    turtle.penup()
 
 
# 第一个画面,显示文字
def page0():
    turtle.penup()
    turtle.goto(-350, 0)
    turtle.color('black')
    turtle.write('专属于我们的情人节', font=('新宋体', 60, 'normal'))
    time.sleep(3)
 
 
# 第二个画面,显示发射爱心的小人
def page1():
    turtle.speed(10)
    draw_people(-250, 20)
    turtle.penup()
    turtle.goto(-150, -30)
    draw_heart(14)
    turtle.penup()
    turtle.goto(-20, -60)
    draw_heart(25)
    turtle.penup()
    turtle.goto(250, -100)
    draw_heart(45)
    turtle.hideturtle()
    time.sleep(3)
 
 
# 最后一个画面,一箭穿心
def page2():
    turtle.speed(1)
    turtle.penup()
    turtle.goto(-200, -200)
    turtle.color('blue')
    turtle.pendown()
    turtle.write('SBB       HYQ', font=('wisdom', 50, 'normal'))
    turtle.penup()
    turtle.goto(0, -180)
    draw_heart(10)
    arrow_heart(20, -60, 51)
    turtle.showturtle()
 
 
def main():
    turtle.setup(900, 500)
    page0()
    clear_all()
    page1()
    clear_all()
    page2()
    turtle.done()
 
 
main()

3.告白(二)

# Project Leader:苏
# Project:表白源码


import turtle
import random

def love(x,y):  # 在(x,y)处画爱心lalala
    lv=turtle.Turtle()

    lv.hideturtle()

    lv.up()

    lv.goto(x,y)#定位到(x,y)

    def curvemove():#画圆弧
        for i in range(20):
            lv.right(10)
            lv.forward(2)
    lv.color('red','pink')

    lv.speed(10000000)

    lv.pensize(1)

    #开始画爱心lalala

    lv.down()

    lv.begin_fill()

    lv.left(140)

    lv.forward(22)

    curvemove()

    lv.left(120)

    curvemove()

    lv.forward(22)

    lv.write("苏彬彬",font=("Arial",12,"normal"),align="center") # 写上表白的人的名字

    lv.left(140)#画完复位

    lv.end_fill()

def tree(branchLen,t):
    if branchLen > 5:#剩余树枝太少要结束递归
        if branchLen<20:

            t.color("green")

            t.pensize(random.uniform((branchLen + 5) / 4 - 2, (branchLen + 6) / 4 + 5))

            t.down()

            t.forward(branchLen)

            love(t.xcor(),t.ycor())#传输现在turtle的坐标

            t.up()

            t.backward(branchLen)

            t.color("brown")

            return

        t.pensize(random.uniform((branchLen+5)/4-2,(branchLen+6)/4+5))

        t.down()

        t.forward(branchLen)

        # 以下递归

        ang=random.uniform(15,45)

        t.right(ang)

        tree(branchLen-random.uniform(12,16),t)#随机决定减小长度

        t.left(2*ang)

        tree(branchLen-random.uniform(12,16),t)#随机决定减小长度

        t.right(ang)

        t.up()

        t.backward(branchLen)

myWin = turtle.Screen()

t = turtle.Turtle()

t.hideturtle()

t.speed(1000)

t.left(90)

t.up()

t.backward(200)

t.down()

t.color("brown")

t.pensize(32)

t.forward(60)

tree(100,t)

myWin.exitonclick() 

4.告白(二)

import turtle
import time


def clear_all():
    turtle.penup()
    turtle.goto(0, 0)
    turtle.color('white')
    turtle.pensize(800)
    turtle.pendown()
    turtle.setheading(0)
    turtle.fd(300)
    turtle.bk(600)


def go_to(x, y, state):
    turtle.pendown() if state else turtle.penup()
    turtle.goto(x, y)


def draw_line(length, angle, state):
    turtle.pensize(1)
    turtle.pendown()
    turtle.setheading(angle)
    turtle.fd(length)
    turtle.bk(length) if state else turtle.penup()
    turtle.penup()


def draw_feather(size):
    angle = 30  
    feather_num = size // 6  
    feather_length = size // 3  
    feather_gap = size // 10  
    for i in range(feather_num):
        draw_line(feather_gap, angle + 180, False)  
        draw_line(feather_length, angle + 145, True)  
    draw_line(feather_length, angle + 145, False)
    draw_line(feather_num * feather_gap, angle, False)
    draw_line(feather_length, angle + 145 + 180, False)
    for i in range(feather_num):
        draw_line(feather_gap, angle + 180, False)  
        draw_line(feather_length, angle - 145, True) 
    draw_line(feather_length, angle - 145, False)
    draw_line(feather_num * feather_gap, angle, False)
    draw_line(feather_length, angle - 145 + 180, False)


def draw_heart(size):
    turtle.color('red', 'pink')
    turtle.pensize(2)
    turtle.pendown()
    turtle.setheading(150)
    turtle.begin_fill()
    turtle.fd(size)
    turtle.circle(size * -3.745, 45)
    turtle.circle(size * -1.431, 165)
    turtle.left(120)
    turtle.circle(size * -1.431, 165)
    turtle.circle(size * -3.745, 45)
    turtle.fd(size)
    turtle.end_fill()


def draw_arrow(size):
    angle = 30
    turtle.color('black')
    draw_feather(size)
    turtle.pensize(4)
    turtle.setheading(angle)
    turtle.pendown()
    turtle.fd(size * 2)


def arrow_heart(x, y, size):
    go_to(x, y, False)
    draw_heart(size * 1.15)
    turtle.setheading(-150)
    turtle.penup()
    turtle.fd(size * 2.2)
    draw_heart(size)
    turtle.penup()
    turtle.setheading(150)
    turtle.fd(size * 2.2)
    draw_arrow(size)


def draw_people(x, y):
    turtle.penup()
    turtle.goto(x, y)
    turtle.pendown()
    turtle.pensize(2)
    turtle.color('black')
    turtle.setheading(0)
    turtle.circle(60, 360)
    turtle.penup()
    turtle.setheading(90)
    turtle.fd(75)
    turtle.setheading(180)
    turtle.fd(20)
    turtle.pensize(4)
    turtle.pendown()
    turtle.circle(2, 360)
    turtle.setheading(0)
    turtle.penup()
    turtle.fd(40)
    turtle.pensize(4)
    turtle.pendown()
    turtle.circle(-2, 360)
    turtle.penup()
    turtle.goto(x, y)
    turtle.setheading(-90)
    turtle.pendown()
    turtle.fd(20)
    turtle.setheading(0)
    turtle.fd(35)
    turtle.setheading(60)
    turtle.fd(10)
    turtle.penup()
    turtle.goto(x, y)
    turtle.setheading(-90)
    turtle.pendown()
    turtle.fd(40)
    turtle.setheading(0)
    turtle.fd(35)
    turtle.setheading(-60)
    turtle.fd(10)
    turtle.penup()
    turtle.goto(x, y)
    turtle.setheading(-90)
    turtle.pendown()
    turtle.fd(60)
    turtle.setheading(-135)
    turtle.fd(60)
    turtle.bk(60)
    turtle.setheading(-45)
    turtle.fd(30)
    turtle.setheading(-135)
    turtle.fd(35)
    turtle.penup()


def page0():
    turtle.penup()
    turtle.goto(-350, 0)
    turtle.color('black')
    turtle.write('LOVE', font=('黑体', 60, 'normal'))
    time.sleep(3)


def page1():
    turtle.speed(10)
    draw_people(-250, 20)
    turtle.penup()
    turtle.goto(-150, -30)
    draw_heart(14)
    turtle.penup()
    turtle.goto(-20, -60)
    draw_heart(25)
    turtle.penup()
    turtle.goto(250, -100)
    draw_heart(45)
    turtle.hideturtle()
    time.sleep(3)


def page2():
    turtle.speed(1)
    turtle.penup()
    turtle.goto(-200, -200)
    turtle.color('blue')
    turtle.pendown()
    turtle.write('HRQ       SBB', font=('wisdom', 50, 'normal'))
    turtle.penup()
    turtle.goto(0, -180)
    draw_heart(10)
    arrow_heart(20, -60, 51)
    turtle.showturtle()


def main():
    turtle.setup(900, 500)
    page0()
    clear_all()
    page1()
    clear_all()
    page2()
    turtle.done()


main()

5.哆啦A梦

# * -- utf-8 -- *
# Author: Tang

import turtle as t

t.speed(10)
t.pensize(8)
t.hideturtle()
t.screensize(500, 500, bg='white')

# �
t.fillcolor('#00A1E8')
t.begin_fill()
t.circle(120)
t.end_fill()

t.pensize(3)
t.fillcolor('white')
t.begin_fill()
t.circle(100)
t.end_fill()

t.pu()
t.home()
t.goto(0, 134)
t.pd()
t.pensize(4)
t.fillcolor("#EA0014")
t.begin_fill()
t.circle(18)
t.end_fill()

t.pu()
t.goto(7, 155)
t.pensize(2)
t.color('white', 'white')
t.pd()
t.begin_fill()
t.circle(4)
t.end_fill()

t.pu()
t.goto(-30, 160)
t.pensize(4)
t.pd()
t.color('black', 'white')
t.begin_fill()
a = 0.4
for i in range(120):
    if 0 <= i < 30 or 60 <= i < 90:
        a = a + 0.08
        t.lt(3)  # ����ת3��
        t.fd(a)  # ��ǰ��a�IJ���
    else:
        a = a - 0.08
        t.lt(3)
        t.fd(a)
t.end_fill()

t.pu()
t.goto(30, 160)
t.pensize(4)
t.pd()
t.color('black', 'white')
t.begin_fill()
for i in range(120):
    if 0 <= i < 30 or 60 <= i < 90:
        a = a + 0.08
        t.lt(3)  # ����ת3��
        t.fd(a)  # ��ǰ��a�IJ���
    else:
        a = a - 0.08
        t.lt(3)
        t.fd(a)
t.end_fill()

t.pu()
t.goto(-38, 190)
t.pensize(8)
t.pd()
t.right(-30)
t.forward(15)
t.right(70)
t.forward(15)

t.pu()
t.goto(15, 185)
t.pensize(4)
t.pd()
t.color('black', 'black')
t.begin_fill()
t.circle(13)
t.end_fill()

t.pu()
t.goto(13, 190)
t.pensize(2)
t.pd()
t.color('white', 'white')
t.begin_fill()
t.circle(5)
t.end_fill()

t.pu()
t.home()
t.goto(0, 134)
t.pensize(4)
t.pencolor('black')
t.pd()
t.right(90)
t.forward(40)

t.pu()
t.home()
t.goto(0, 124)
t.pensize(3)
t.pencolor('black')
t.pd()
t.left(10)
t.forward(80)

t.pu()
t.home()
t.goto(0, 114)
t.pensize(3)
t.pencolor('black')
t.pd()
t.left(6)
t.forward(80)

t.pu()
t.home()
t.goto(0, 104)
t.pensize(3)
t.pencolor('black')
t.pd()
t.left(0)
t.forward(80)

# ��ߵĺ���
t.pu()
t.home()
t.goto(0, 124)
t.pensize(3)
t.pencolor('black')
t.pd()
t.left(170)
t.forward(80)

t.pu()
t.home()
t.goto(0, 114)
t.pensize(3)
t.pencolor('black')
t.pd()
t.left(174)
t.forward(80)

t.pu()
t.home()
t.goto(0, 104)
t.pensize(3)
t.pencolor('black')
t.pd()
t.left(180)
t.forward(80)

t.pu()
t.goto(-70, 70)
t.pd()
t.color('black', 'red')
t.pensize(6)
t.seth(-60)
t.begin_fill()
t.circle(80, 40)
t.circle(80, 80)
t.end_fill()

t.pu()
t.home()
t.goto(-80, 70)
t.pd()
t.forward(160)

t.pu()
t.home()
t.goto(-50, 50)
t.pd()
t.pensize(1)
t.fillcolor("#eb6e1a")
t.seth(40)
t.begin_fill()
t.circle(-40, 40)
t.circle(-40, 40)
t.seth(40)
t.circle(-40, 40)
t.circle(-40, 40)
t.seth(220)
t.circle(-80, 40)
t.circle(-80, 40)
t.end_fill()

# ���
t.pu()
t.goto(-70, 12)
t.pensize(14)
t.pencolor('red')
t.pd()
t.seth(-20)
t.circle(200, 30)
t.circle(200, 10)

# ����
t.pu()
t.goto(0, -46)
t.pd()
t.pensize(3)
t.color("black", '#f8d102')
t.begin_fill()
t.circle(25)
t.end_fill()

t.pu()
t.goto(-5, -40)
t.pd()
t.pensize(2)
t.color("black", '#79675d')
t.begin_fill()
t.circle(5)
t.end_fill()

t.pensize(3)
t.right(115)
t.forward(7)

t.mainloop()

6.爱心发射

 from turtle import *
from time import sleep
 
def go_to(x, y):
   up()
   goto(x, y)
   down()
 
def head(x,y,r):
    go_to(x,y)
    speed(1)
    circle(r)
    leg(x,y)
 
def leg(x,y):
 
    right(90)
    forward(180)
    right(30)
    forward(100)
    left(120)
    go_to(x,y-180)
    forward(100)
    right(120)
    forward(100)
    left(120)
    hand(x,y)
 
 
def hand(x,y):
    go_to(x,y-60)
    forward(100)
    left(60)
    forward(100)
    go_to(x, y - 90)
    right(60)
    forward(100)
    right(60)
    forward(100)
    left(60)
    eye(x,y)
 
def eye(x,y):
    go_to(x-50,y+130)
    right(90)
    forward(50)
    go_to(x+40,y+130)
    forward(50)
    left(90)
 
 
def big_Circle(size):
   speed(20)
   for i in range(150):
       forward(size)
       right(0.3)
def line(size):
   speed(1)
   forward(51*size)
 
def small_Circle(size):
   speed(10)
   for i in range(210):
       forward(size)
       right(0.786)
 
 
 
def heart(x, y, size):
   go_to(x, y)
   left(150)
   begin_fill()
   line(size)
   big_Circle(size)
   small_Circle(size)
   left(120)
   small_Circle(size)
   big_Circle(size)
   line(size)
   end_fill()
 
def main():
    pensize(2)
    color('red', 'pink')
    head(-120, 100, 100)
    heart(250, -80, 1)
    go_to(200, -300)
    write("To: 智慧与美貌并存的", move=True, align="left", font=("楷体", 20, "normal"))
    done()
 
main()

7.玫瑰花

# coding: utf-8

# In[2]:

from turtle import *
import time

setup(600, 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()

8.画星星

import turtle as t
t.goto(100, 0)

for i in range(50):
	t.left(80)
	t.fd(100)
	t.left(135)
	t.fd(105)

9.一箭穿心

from turtle import *
from time import sleep
 
def go_to(x, y):
   up()
   goto(x, y)
   down()
 
def big_Circle(size):  #函数用于绘制心的大圆
   speed(5)
   for i in range(150):
       forward(size)
       right(0.3)
 
def small_Circle(size):  #函数用于绘制心的小圆
   speed(10)
   for i in range(210):
       forward(size)
       right(0.786)
 
def line(size):
   speed(5)
   forward(51*size)
 
def heart( x, y, size):
   go_to(x, y)
   left(150)
   begin_fill()
   line(size)
   big_Circle(size)
   small_Circle(size)
   left(120)
   small_Circle(size)
   big_Circle(size)
   line(size)
   end_fill()
 
def arrow():
   pensize(10)
   setheading(0)
   go_to(-400, 0)
   left(15)
   forward(150)
   go_to(339, 178)
   forward(150)
 
def arrowHead():
   pensize(1)
   speed(5)
   color('red', 'red')
   begin_fill()
   left(120)
   forward(20)
   right(150)
   forward(35)
   right(120)
   forward(35)
   right(150)
   forward(20)
   end_fill()
 
def main():
   pensize(4)
   color('red', 'pink')
   #getscreen().tracer(30, 0) #取消注释后,快速显示图案
   heart(200, 0, 1)          #画出第一颗心,前面两个参数控制心的位置,函数最后一个参数可控制心的大小
   setheading(0)             #使画笔的方向朝向x轴正方向
   heart(-80, -100, 1.5)     #画出第二颗心
   arrow()                   #画出穿过两颗心的直线
   arrowHead()               #画出箭的箭头
   go_to(400, -300)
   done()
main()

本文地址:https://blog.csdn.net/weixin_45713061/article/details/109038456