对于详细的Python简单运行操作,建议您关注公众号"己墨日志"去看有关于python画图的文章,会手把手教你把这个动图运行起来的!
No.1
效果
源代码
import turtle import math turtle.pen() t=turtle t.up() t.goto(0,150) t.down() t.color('red') t.begin_fill() t.fillcolor('red') t.speed(1) t.left(45) t.forward(150) t.right(45) t.forward(100) t.right(45) t.forward(100) t.right(45) t.forward(100) t.right(45) t.forward(250+math.sqrt(2)*100) t.right (90) t.speed(2) t.forward(250+100*math.sqrt(2)) t.right(45) t.forward(100) t.right(45) t.forward(100) t.right(45) t.forward(100) t.right(45) t.forward(150) t.end_fill() t.goto(-10,0) t.pencolor('white') #L t.pensize(10) t.goto(-50,0) t.goto(-50,80) t.up () #I t.goto(-100,0) t.down() t.goto(-160,0) t.goto(-130,0) t.goto(-130,80) t.goto(-160,80) t.goto(-100,80) t.up() #O t.goto(10,25) t.down() t.right(45) t.circle(25,extent=180) t.goto(60,55) t.circle(25,extent=180) t.goto(10,25) t.up() t.goto(75,80) t.down() t.goto(100,0) t.goto(125,80) t.up() t.goto(180,80) t.down() t.goto(140,80) t.goto(140,0) t.goto(180,0) t.up() t.goto(180,40) t.down() t.goto(140,40) #U t.up() t.goto(-40,-30) t.down() t.goto(-40,-80) t.circle(40,extent=180) t.goto(40,-30) t.hideturtle()
No.2
效果
源代码
#!/usr/bin/env python # coding: utf-8 #绘制玫瑰花并添加文字 import turtle # 设置画布大小 # turtle.screensize(canvwidth=None, canvheight=None, bg=None) turtle.setup(width=0.6, height=0.6) # 设置初始位置 turtle.penup() turtle.left(90) turtle.fd(200) turtle.pendown() turtle.right(90) # 输出文字 printer = turtle.Turtle() printer.hideturtle() printer.penup() printer.back(200) printer.write("赠给亲爱的 QQ\n\n", align="right", font=("楷体", 16, "bold")) printer.write("from XXX", align="center", font=("楷体", 12, "normal")) # 花蕊 turtle.fillcolor("red") turtle.begin_fill() turtle.circle(10, 180) turtle.circle(25, 110) turtle.left(50) turtle.circle(60, 45) turtle.circle(20, 170) turtle.right(24) turtle.fd(30) turtle.left(10) turtle.circle(30, 110) turtle.fd(20) turtle.left(40) turtle.circle(90, 70) turtle.circle(30, 150) turtle.right(30) turtle.fd(15) turtle.circle(80, 90) turtle.left(15) turtle.fd(45) turtle.right(165) turtle.fd(20) turtle.left(155) turtle.circle(150, 80) turtle.left(50) turtle.circle(150, 90) turtle.end_fill() # 花瓣1 turtle.left(150) turtle.circle(-90, 70) turtle.left(20) turtle.circle(75, 105) turtle.setheading(60) turtle.circle(80, 98) turtle.circle(-90, 40) # 花瓣2 turtle.left(180) turtle.circle(90, 40) turtle.circle(-80, 98) turtle.setheading(-83) # 叶子1 turtle.fd(30) turtle.left(90) turtle.fd(25) turtle.left(45) turtle.fillcolor("green") turtle.begin_fill() turtle.circle(-80, 90) turtle.right(90) turtle.circle(-80, 90) turtle.end_fill() turtle.right(135) turtle.fd(60) turtle.left(180) turtle.fd(85) turtle.left(90) turtle.fd(80) # 叶子2 turtle.right(90) turtle.right(45) turtle.fillcolor("green") turtle.begin_fill() turtle.circle(80, 90) turtle.left(90) turtle.circle(80, 90) turtle.end_fill() turtle.left(135) turtle.fd(60) turtle.left(180) turtle.fd(60) turtle.right(90) turtle.circle(200, 60) turtle.done()
No.3
效果
源代码
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("YZ", 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()
No.4
效果
源代码
# -*- coding: utf-8 -*- # @Time : 18-12-26 上午9:32 # @Author : Felix Wang import turtle # 定义圣诞树的绿叶函数 def tree(d, s): if d <= 0: return turtle.forward(s) tree(d - 1, s * .8) turtle.right(120) tree(d - 3, s * .5) turtle.right(120) tree(d - 3, s * .5) turtle.right(120) turtle.backward(s) n = 100 """ 设置绘图速度 'fastest' : 0 'fast' : 10 'normal' : 6 'slow' : 3 'slowest' : 1 """ turtle.speed('fastest') # 设置速度 turtle.left(90) turtle.forward(3 * n) turtle.color("orange", "yellow") turtle.left(126) # turtle.begin_fill() for i in range(5): turtle.forward(n / 5) turtle.right(144) turtle.forward(n / 5) turtle.left(72) turtle.end_fill() turtle.right(126) turtle.color("dark green") turtle.backward(n * 4.8) # 执行函数 tree(15, n) turtle.backward(n / 5)