Python 官方文档:入门教程 => 点击学习
1 炫酷彩虹 视频是动态的,不信你运行试试。 from turtle import *colors = ["red", "yellow", "blue", "lime"]bGColor("black")x = 6t = [Turt
视频是动态的,不信你运行试试。
from turtle import *colors = ["red", "yellow", "blue", "lime"]bGColor("black")x = 6t = [Turtle(), Turtle()]for index, i in enumerate(t): i.speed(0) i.color("white") i.shape("circle") i.shapesize(0.3) i.width(3) i.pu() i.seth(90) i.fd(350) i.seth(-180) i.pd()t[0].pu()delay(0)speed(0)ht()for i in colors: color(i) for i in range(360): t[0].fd(x) t[0].lt(1) pu() Goto(t[0].pos()) pd() t[1].fd(2 * x) t[1].lt(2) goto(t[1].pos())done()
import turtle as tdef hair(): # 画头发 t.penup() t.goto(-50, 150) t.pendown() t.fillcolor('#a2774d') t.begin_fill() for j in range(10): # 重复执行10次 t.setheading(60 - (j * 36)) # 每次调整初始角度 t.circle(-50, 120) # 画120度的弧 t.end_fill()def face(): # 画脸 t.penup() t.goto(0, 100) t.pendown() t.fillcolor('#f2ae20') t.begin_fill() t.setheading(180) t.circle(85) t.end_fill() # 下巴 t.circle(85, 120) t.fillcolor('white') t.begin_fill() t.circle(85, 120) t.setheading(135) t.circle(100, 95) t.end_fill()def ears(dir): # 画眼睛,dir用来设置方向,左右眼对称 t.penup() t.goto((0 - dir) * 30, 90) t.setheading(90) t.pendown() t.fillcolor('#f2ae20') t.begin_fill() t.circle(dir * 30) t.end_fill() t.penup() t.goto((0 - dir) * 40, 85) t.setheading(90) t.pendown() t.fillcolor('white') t.begin_fill() t.circle(dir * 17) t.end_fill()def nose(): # 画鼻子 t.penup() t.goto(20, 0) t.setheading(90) t.pendown() t.fillcolor('#a2774d') t.begin_fill() t.circle(20) t.end_fill()def eye(dir): # 画耳朵,dir用来设置方向,左右耳对称 t.penup() t.goto((0 - dir) * 30, 20) t.setheading(0) t.pendown() t.fillcolor('black') t.begin_fill() t.circle(10) t.end_fill()def mouth(): # 画嘴巴 t.penup() t.goto(0, 0) t.setheading(-90) t.pendown() t.forward(50) t.setheading(0) t.circle(80, 30) t.penup() t.goto(0, -50) t.setheading(180) t.pendown() t.circle(-80, 30)hair()ears(1)ears(-1)face()eye(1)eye(-1)mouth()nose()t.done()
from turtle import *from colorsys import *def curve(): for i in range(200): right(1) forward(1)tracer(10)delay(0)speed(0)pensize(3)bgcolor("black")left(140)cycles_number = 2for _ in range(cycles_number): s = 1 for i in range(36): color("#C90055", hsv_to_rgb(0.92, s, 1)) begin_fill() forward(111.65) curve() left(120) curve() forward(111.65) end_fill() hideturtle() right(90) s -= 0.02done()
import turtleimport tkinter as tkdef draw_spiral(): colors = ["red", "orange", "yellow", "green", "blue", "purple"] turtle.speed(0) turtle.bgcolor("black") for i in range(360): turtle.color(colors[i % 6]) turtle.width(i / 100 + 1) turtle.forward(i) turtle.left(59)def main(): # 创建绘图窗口 window = tk.Tk() window.title("炫酷螺旋线") # 在绘图窗口中显示螺旋线 draw_spiral() # 关闭绘图窗口的函数 def close_window(): window.destroy() # 创建关闭按钮 close_button = tk.Button(window, text="关闭", command=close_window) close_button.pack() # 运行Tkinter事件循环 tk.mainloop()if __name__ == "__main__": main()
import turtleimport timet = turtle.Turtle()t.speed(1)# 设置初始位置t.penup()t.left(90)t.fd(200)t.pendown()t.right(90)# 花蕊t.fillcolor("red")t.begin_fill()t.circle(10, 180)t.circle(25, 110)t.left(50)t.circle(60, 45)t.circle(20, 170)t.right(24)t.fd(30)t.left(10)t.circle(30, 110)t.fd(20)t.left(40)t.circle(90, 70)t.circle(30, 150)t.right(30)t.fd(15)t.circle(80, 90)t.left(15)t.fd(45)t.right(165)t.fd(20)t.left(155)t.circle(150, 80)t.left(50)t.circle(150, 90)t.end_fill()# 花瓣1t.left(150)t.circle(-90, 70)t.left(20)t.circle(75, 105)t.setheading(60)t.circle(80, 98)t.circle(-90, 40)# 花瓣2t.left(180)t.circle(90, 40)t.circle(-80, 98)t.setheading(-83)# 叶子1t.fd(30)t.left(90)t.fd(25)t.left(45)t.fillcolor("green")t.begin_fill()t.circle(-80, 90)t.right(90)t.circle(-80, 90)t.end_fill()t.right(135)t.fd(60)t.left(180)t.fd(85)t.left(90)t.fd(80)# 叶子2t.right(90)t.right(45)t.fillcolor("green")t.begin_fill()t.circle(80, 90)t.left(90)t.circle(80, 90)t.end_fill()t.left(135)t.fd(60)t.left(180)t.fd(60)t.right(90)t.circle(200, 60)time.sleep(5)
from turtle import *def curvemove(): for i in range(200): right(1) forward(1)setup(600, 600, 600, 600)hideturtle()pencolor('black')fillcolor("red")pensize(2)begin_fill()left(140)forward(111.65)curvemove()left(120)curvemove()forward(111.65)end_fill()penup()goto(-27, 85)pendown()done()
# coding:utf-8import turtle as timport time# 皮卡丘# 基础设置t.screensize(800, 600)t.pensize(2) # 设置画笔的大小t.speed(10) # 设置画笔速度为10# 画左偏曲线函数def radian_left(ang, dis, step, n): for i in range(n): dis += step # dis增大step t.lt(ang) # 向左转ang度 t.fd(dis) # 向前走dis的步长def radian_right(ang, dis, step, n): for i in range(n): dis += step t.rt(ang) # 向左转ang度 t.fd(dis) # 向前走dis的步长# 画耳朵def InitEars(): t.color("black", "yellow") # 左耳朵曲线 t.pu() # 提笔 t.goto(-50, 100) # 笔头初始位置 t.pd() # 下笔 t.setheading(110) # 画笔角度 t.begin_fill() radian_left(1.2, 0.4, 0.1, 40) t.setheading(270) # 画笔角度 radian_left(1.2, 0.4, 0.1, 40) t.setheading(44) # 画笔角度 t.forward(32) t.end_fill() # 右耳朵曲线 t.pu() # 提笔 t.goto(50, 100) # 笔头初始位置 t.pd() # 下笔 t.setheading(70) # 画笔角度 t.begin_fill() radian_right(1.2, 0.4, 0.1, 40) t.setheading(270) # 画笔角度 radian_right(1.2, 0.4, 0.1, 40) t.setheading(136) # 画笔角度 t.forward(32) t.end_fill() # 耳朵黑 t.begin_fill() t.fillcolor("black") t.pu() # 提笔 t.goto(88, 141) # 笔头初始位置 t.pd() # 下笔 t.setheading(35) # 画笔角度 radian_right(1.2, 1.6, 0.1, 16) t.setheading(270) # 画笔角度 radian_right(1.2, 0.4, 0.1, 25) t.setheading(132) # 画笔角度 t.forward(31) t.end_fill() t.begin_fill() t.fillcolor("black") t.pu() # 提笔 t.goto(-88, 141) # 笔头初始位置 t.pd() # 下笔 t.setheading(145) # 画笔角度 radian_left(1.2, 1.6, 0.1, 16) t.setheading(270) # 画笔角度 radian_left(1.2, 0.4, 0.1, 25) t.setheading(48) # 画笔角度 t.forward(31) t.end_fill()# 画尾巴def InitTail(): # 尾巴 t.begin_fill() t.fillcolor("yellow") t.pu() # 提笔 t.goto(64, -140) # 笔头初始位置 t.pd() # 下笔 t.setheading(10) # 画笔角度 t.forward(20) t.setheading(90) # 画笔角度 t.forward(20) t.setheading(10) # 画笔角度 t.forward(10) t.setheading(80) # 画笔角度 t.forward(100) t.setheading(35) # 画笔角度 t.forward(80) t.setheading(260) # 画笔角度 t.forward(100) t.setheading(205) # 画笔角度 t.forward(40) t.setheading(260) # 画笔角度 t.forward(37) t.setheading(205) # 画笔角度 t.forward(20) t.setheading(260) # 画笔角度 t.forward(25) t.setheading(175) # 画笔角度 t.forward(30) t.setheading(100) # 画笔角度 t.forward(13) t.end_fill()# 画脚def InitFoots(): # 脚 t.begin_fill() t.fillcolor("yellow") t.pensize(2) t.pu() # 提笔 t.goto(-70, -200) # 笔头初始位置 t.pd() # 下笔 t.setheading(225) # 画笔角度 radian_left(0.5, 1.2, 0, 12) radian_left(35, 0.6, 0, 4) radian_left(1, 1.2, 0, 18) t.setheading(160) # 画笔角度 t.forward(13) t.end_fill() t.begin_fill() t.fillcolor("yellow") t.pensize(2) t.pu() # 提笔 t.goto(70, -200) # 笔头初始位置 t.pd() # 下笔 t.setheading(315) # 画笔角度 radian_right(0.5, 1.2, 0, 12) radian_right(35, 0.6, 0, 4) radian_right(1, 1.2, 0, 18) t.setheading(20) # 画笔角度 t.forward(13) t.end_fill()# 画身体def InitBody(): # 外形轮廓 t.begin_fill() t.pu() # 提笔 t.goto(112, 0) # 笔头初始位置 t.pd() # 下笔 t.setheading(90) # 画笔角度 t.circle(112, 180) t.setheading(250) # 画笔角度 radian_left(1.6, 1.3, 0, 50) radian_left(0.8, 1.5, 0, 25) t.setheading(255) # 画笔角度 radian_left(0.4, 1.6, 0.2, 27) radian_left(2.8, 1, 0, 45) radian_right(0.9, 1.4, 0, 31) t.setheading(355) # 画笔角度 radian_right(0.9, 1.4, 0, 31) radian_left(2.8, 1, 0, 45) radian_left(0.4, 7.2, -0.2, 27) t.setheading(10) # 画笔角度 radian_left(0.8, 1.5, 0, 25) radian_left(1.6, 1.3, 0, 50) t.end_fill()def InitEyes(): # 左眼睛 t.begin_fill() t.fillcolor("black") t.pu() # 提笔 t.goto(-46, 10) # 笔头初始位置 t.pd() # 下笔 t.setheading(90) # 画笔角度 t.circle(5, 360) t.end_fill() # 右眼睛 t.begin_fill() t.fillcolor("black") t.pu() # 提笔 t.goto(46, 10) # 笔头初始位置 t.pd() # 下笔 t.setheading(-90) # 画笔角度 t.circle(5, 360) t.end_fill()# 画脸def InitFace(): # 脸蛋 t.begin_fill() t.fillcolor("red") t.pu() # 提笔 t.goto(-63, -10) # 笔头初始位置 t.pd() # 下笔 t.setheading(90) # 画笔角度 t.circle(10, 360) t.end_fill() t.begin_fill() t.fillcolor("red") t.pu() # 提笔 t.goto(63, -10) # 笔头初始位置 t.pd() # 下笔 t.setheading(-90) # 画笔角度 t.circle(10, 360) t.end_fill() # 嘴巴 t.pensize(2.2) t.pu() # 提笔 t.goto(0, 0) # 笔头初始位置 t.pd() # 下笔 t.setheading(235) # 画笔角度 radian_right(5, 0.8, 0, 30) t.pu() # 提笔 t.goto(0, 0) # 笔头初始位置 t.pd() # 下笔 t.setheading(305) # 画笔角度 radian_left(5, 0.8, 0, 30)# 画手def InitHands(): # 左手 t.pensize(2) t.pu() # 提笔 t.goto(-46, -100) # 笔头初始位置 t.pd() # 下笔 t.setheading(285) # 画笔角度 radian_right(0.4, 1.2, 0, 26) radian_right(5, 0.35, 0, 26) radian_right(0.3, 1.2, 0, 15) # 右手 t.pu() # 提笔 t.goto(46, -100) # 笔头初始位置 t.pd() # 下笔 t.setheading(255) # 画笔角度 radian_left(0.4, 1.2, 0, 26) radian_left(5, 0.35, 0, 26) radian_left(0.3, 1.2, 0, 15)def CloseEyes(): # 左眼睛 t.pu() # 提笔 t.goto(-46, 12) # 笔头初始位置 t.pd() # 下笔 t.setheading(180) # 画笔角度 t.forward(10) # 右眼睛 t.pu() # 提笔 t.goto(46, 12) # 笔头初始位置 t.pd() # 下笔 t.setheading(0) # 画笔角度 t.forward(10)# 初始化def Init(): InitEars() InitTail() InitFoots() InitBody() InitFace() InitHands() InitEyes()# 眨眼睛def Upgarde(): InitEars() InitTail() InitFoots() InitBody() InitFace() InitHands() CloseEyes()def Upgarde_Init(): InitEars() InitTail() InitFoots() InitBody() InitFace() InitHands() InitEyes()def main(): Init() t.tracer(False) # 眨眼睛动画 for i in range(30): if i % 2 == 0: t.reset() t.hideturtle() Upgarde() t.update() time.sleep(0.3) else: t.reset() t.hideturtle() Upgarde_Init() t.update() time.sleep(1)main()# 结束画笔t.done()
import turtlefrom turtle import *turtle.title('小猪佩奇')def nose(x, y): """画鼻子""" pensize(5) pencolor((255, 155, 192)) penup() # 将海龟移动到指定的坐标 goto(x, y) pendown() # 设置海龟的方向(0-东、90-北、180-西、270-南) setheading(-30) begin_fill() fillcolor(255, 192, 203) a = 0.4 for i in range(120): if 0 <= i < 30 or 60 <= i < 90: a = a + 0.08 # 向左转3度 left(3) # 向前走 forward(a) else: a = a - 0.08 left(3) forward(a) end_fill() penup() setheading(90) forward(25) setheading(0) forward(10) pendown() """设置画笔的颜色(红, 绿, 蓝)""" pencolor(255, 155, 192) setheading(10) begin_fill() circle(5) color(160, 82, 45) end_fill() penup() setheading(0) forward(20) pendown() pencolor(255, 155, 192) setheading(10) begin_fill() circle(5) color(160, 82, 45) end_fill()def head(x, y): """画头""" color((255, 155, 192), "pink") penup() goto(x, y) setheading(0) pendown() begin_fill() setheading(180) circle(300, -30) circle(100, -60) circle(80, -100) circle(150, -20) circle(60, -95) setheading(161) circle(-300, 15) penup() goto(-100, 100) pendown() setheading(-30) a = 0.4 for i in range(60): if 0 <= i < 30 or 60 <= i < 90: a = a + 0.08 lt(3) # 向左转3度 fd(a) # 向前走a的步长 else: a = a - 0.08 lt(3) fd(a) end_fill()def ears(x, y): """画耳朵""" color((255, 155, 192), "pink") penup() goto(x, y) pendown() begin_fill() setheading(100) circle(-50, 50) circle(-10, 120) circle(-50, 54) end_fill() penup() setheading(90) forward(-12) setheading(0) forward(30) pendown() begin_fill() setheading(90) circle(-50, 50) circle(-10, 120) circle(-50, 56) end_fill()def eyes(x, y): """画眼睛""" color((255, 155, 192), "white") penup() setheading(90) forward(-20) setheading(0) forward(-95) pendown() begin_fill() circle(15) end_fill() color("black") penup() setheading(90) forward(12) setheading(0) forward(-3) pendown() begin_fill() circle(3) end_fill() color((255, 155, 192), "white") penup() seth(90) forward(-25) seth(0) forward(40) pendown() begin_fill() circle(15) end_fill() color("black") penup() setheading(90) forward(12) setheading(0) forward(-3) pendown() begin_fill() circle(3) end_fill()def cheek(x, y): """画脸颊""" color((255, 155, 192)) penup() goto(x, y) pendown() setheading(0) begin_fill() circle(30) end_fill()def mouth(x, y): """画嘴巴""" color(239, 69, 19) penup() goto(x, y) pendown() setheading(-80) circle(30, 40) circle(40, 80)def body(x, y): '''画身体''' penup() goto(x, y) pencolor('red') fillcolor(250, 106, 106) pendown() begin_fill() setheading(-66) circle(-450, 17) setheading(180) forward(185) setheading(85) circle(-450, 17) end_fill() '''右手''' penup() goto(110, -45) pendown() pensize(8) pencolor(255, 192, 203) setheading(30) circle(-400, 10) penup() goto(167, -5) pendown() setheading(-120) forward(20) left(100) forward(20) '''左手''' penup() goto(-25, -45) pendown() pencolor(255, 192, 203) setheading(150) circle(400, 10) penup() goto(-78, -6) pendown() setheading(-60) forward(20) right(100) forward(20)def feet1(x, y): pensize(7) pencolor(255, 192, 203) penup() goto(x, y) setheading(-90) pendown() forward(10) penup() goto(x - 12, y - 10) pendown() pencolor(238, 201, 0) fillcolor(238, 230, 132) begin_fill() setheading(0) forward(24) right(90) forward(36) right(90) forward(40) circle(-10, 180) forward(16) left(90) forward(12) end_fill()def feet2(x, y): pensize(7) pencolor(255, 192, 203) penup() goto(x, y) setheading(-90) pendown() forward(10) penup() goto(x - 12, y - 10) pendown() pencolor(238, 201, 0) fillcolor(238, 230, 132) begin_fill() setheading(0) forward(24) right(90) forward(36) right(90) forward(40) circle(-10, 180) forward(16) left(90) forward(12) end_fill()def tail(x, y): pensize(8) penup() goto(x, y) pendown() pencolor(255, 192, 203) setheading(-5) circle(30, 100) circle(10, 180) circle(20, 150)def backg(x): penup() goto(-420, x) setheading(0) fillcolor(50, 205, 50) begin_fill() forward(840) right(90) forward(300) right(90) forward(840) right(90) forward(300) end_fill() setheading(0) fillcolor(0, 191, 255) begin_fill() forward(840) left(90) forward(600) left(90) forward(840) left(90) forward(600) end_fill()def cloude1(x, y): """画云""" penup() goto(x, y) setheading(90) fillcolor(255, 255, 255) begin_fill() a = 0.4 for i in range(120): if 0 <= i < 30 or 60 <= i < 90: a = a + 0.14 # 向左转3度 left(3) # 向前走 forward(a) else: a = a - 0.15 left(3) forward(a) end_fill()def cloude2(x, y): """画云""" penup() goto(x, y) setheading(90) fillcolor(255, 255, 255) begin_fill() a = 0.4 for i in range(120): if 0 <= i < 30 or 60 <= i < 90: a = a + 0.15 # 向左转3度 left(3) # 向前走 forward(a) else: a = a - 0.13 left(3) forward(a) end_fill()def setting(): """设置参数""" pensize(5) # 隐藏海龟 hideturtle() colORMode(255) color((255, 155, 192), "pink") setup(840, 700) speed(10)def main(): """主函数""" setting() backg(0) body(105, -20) nose(-100, 100) head(-69, 167) ears(0, 160) eyes(0, 140) cheek(80, 10) mouth(-20, 30) feet1(10, -150) feet2(90, -150) tail(130, -110) cloude1(-200, 200) cloude2(300, 300) done()if __name__ == '__main__': main()
import turtleimport randomdef 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()
import turtle as t# t = turtle.Turtle()wn = t.Screen()t.colormode(255)t.hideturtle()t.speed(0)t.penup()t.pensize(4)t.goto(100, 0)t.pendown()t.left(90)t.color((0, 0, 0), (255, 255, 0))# 身体绘制上色t.begin_fill()t.forward(200)t.circle(100, 180)t.forward(200)t.circle(100, 180)t.end_fill()# 右眼睛绘制上色t.pensize(12)t.penup()t.goto(-100, 200)t.pendown()t.right(100)t.circle(500, 23)t.pensize(3)t.penup()t.goto(0, 200)t.pendown()t.seth(270)t.color("black", "white")t.begin_fill()t.circle(30)t.end_fill()t.penup()t.goto(15, 200)t.pendown()t.color("black", "black")t.begin_fill()t.circle(15)t.end_fill()t.penup()t.goto(35, 205)t.color("black", "white")t.begin_fill()t.circle(5)t.end_fill()# 左眼睛绘制上色t.pensize(3)t.penup()t.goto(0, 200)t.pendown()t.seth(90)t.color("black", "white")t.begin_fill()t.circle(30)t.end_fill()t.penup()t.goto(-15, 200)t.pendown()t.color("black", "black")t.begin_fill()t.circle(15)t.end_fill()t.penup()t.goto(-35, 205)t.color("black", "white")t.begin_fill()t.circle(5)t.end_fill()# 嘴绘制上色t.penup()t.goto(-20, 100)t.pendown()t.seth(270)t.color("black", "white")t.begin_fill()t.circle(20, 180)t.left(90)t.forward(40)t.end_fill()# 裤子绘制上色t.penup()t.goto(-100, 0)t.pendown()t.seth(0)t.color("black", "blue")t.begin_fill()t.forward(20)t.left(90)t.forward(40)t.right(90)t.forward(160)t.right(90)t.forward(40)t.left(90)t.forward(20)t.seth(270)t.penup()t.goto(-100, 0)t.circle(100, 180)t.end_fill()# 左裤子腰带t.penup()t.goto(-70, 20)t.pendown()t.color("black", "blue")t.begin_fill()t.seth(45)t.forward(15)t.left(90)t.forward(60)t.seth(270)t.forward(15)t.left(40)t.forward(50)t.end_fill()t.left(180)t.goto(-70, 30)t.dot()# 右裤腰带t.penup()t.goto(70, 20)t.pendown()t.color("black", "blue")t.begin_fill()t.seth(135)t.forward(15)t.right(90)t.forward(60)t.seth(270)t.forward(15)t.right(40)t.forward(50)t.end_fill()t.left(180)t.goto(70, 30)t.dot()# 脚t.penup()t.goto(4, -100)t.pendown()t.seth(270)t.color("black", "black")t.begin_fill()t.forward(30)t.left(90)t.forward(40)t.seth(20)t.circle(10, 180)t.circle(400, 2)t.seth(90)t.forward(20)t.goto(4, -100)t.end_fill()t.penup()t.goto(-4, -100)t.pendown()t.seth(270)t.color("black", "black")t.begin_fill()t.forward(30)t.right(90)t.forward(40)t.seth(20)t.circle(10, -225)t.circle(400, -3)t.seth(90)t.forward(21)t.goto(-4, -100)t.end_fill()# 左手t.penup()t.goto(-100, 50)t.pendown()t.seth(225)t.color("black", "yellow")t.begin_fill()t.forward(40)t.left(90)t.forward(35)t.seth(90)t.forward(50)t.end_fill()# 右手t.penup()t.goto(100, 50)t.pendown()t.seth(315)t.color("black", "yellow")t.begin_fill()t.forward(40)t.right(90)t.forward(36)t.seth(90)t.forward(50)t.end_fill()#t.penup()t.goto(0, -100)t.pendown()t.forward(30)#t.penup()t.goto(0, -20)t.pendown()t.color("yellow")t.begin_fill()t.seth(45)t.forward(20)t.circle(10, 180)t.right(90)t.circle(10, 180)t.forward(20)t.end_fill()#t.penup()t.color("black")t.goto(-100, -20)t.pendown()t.circle(30, 90)t.penup()t.goto(100, -20)t.pendown()t.circle(30, -90)# 头顶t.penup()t.goto(2, 300)t.pendown()t.begin_fill()t.seth(135)t.circle(100, 40)t.end_fill()t.penup()t.goto(2, 300)t.pendown()t.begin_fill()t.seth(45)t.circle(100, 40)t.exitonclick()
import timefrom pynput import mouse, keyboardm_keyboard = keyboard.Controller() # 创建一个键盘Qty = int(input("轰炸次数:"))content = input("轰炸内容:")time_Span = int(input("开始轰炸时间(s):"))frequency = float(input("轰炸频率(0.1-0.5):"))print("选择轰炸区域", time_Span, "秒后开始轰炸")time.sleep(time_Span)for i in range(qty): m_keyboard.type(content) # 打字 m_keyboard.press(keyboard.Key.enter) # 按下enter m_keyboard.release(keyboard.Key.enter) # 松开 time.sleep(frequency) # 间隔0.1秒
import turtle as tt.title('哆啦A梦')# t.speed(5)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.4for i in range(120): if 0 <= i < 30 or 60 <= i < 90: a = a + 0.08 t.lt(3) # 向左转3度 t.fd(a) # 向前走a的步长 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的步长 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()
import turtle# 画指定的任意圆弧def arc(sa, ea, x, y, r): # start angle,end angle,circle center,radius turtle.penup() turtle.goto(x, y) turtle.setheading(0) turtle.left(sa) turtle.fd(r) turtle.pendown() turtle.left(90) turtle.circle(r, (ea - sa)) return turtle.position()turtle.hideturtle()# 画脸turtle.speed(5)turtle.setup(900, 600, 200, 200)turtle.pensize(5)turtle.right(90)turtle.penup()turtle.fd(100)turtle.left(90)turtle.pendown()turtle.begin_fill()turtle.pencolor("#B26A0F") # head side colorturtle.circle(150)turtle.fillcolor("#F9E549") # face colorturtle.end_fill()# 画嘴turtle.penup()turtle.goto(77, 20)turtle.pencolor("#744702")turtle.goto(0, 50)turtle.right(30)turtle.fd(110)turtle.right(90)turtle.pendown()turtle.begin_fill()turtle.fillcolor("#925902") # mouth colorturtle.circle(-97, 160)turtle.goto(92, -3)turtle.end_fill()turtle.penup()turtle.goto(77, -25)# 画牙齿turtle.pencolor("white")turtle.begin_fill()turtle.fillcolor("white")turtle.goto(77, -24)turtle.goto(-81, 29)turtle.goto(-70, 43)turtle.goto(77, -8)turtle.end_fill()turtle.penup()turtle.goto(0, -100)turtle.setheading(0)turtle.pendown()# 画左边眼泪turtle.left(90)turtle.penup()turtle.fd(150)turtle.right(60)turtle.fd(-150)turtle.pendown()turtle.left(20)turtle.pencolor("#155F84") # tear side colorturtle.fd(150)turtle.right(180)position1 = turtle.position()turtle.begin_fill()turtle.fillcolor("#7EB0C8") # tear colorturtle.fd(150)turtle.right(20)turtle.left(270)turtle.circle(-150, 18)turtle.right(52)turtle.fd(110)position2 = turtle.position()turtle.goto(-33, 90)turtle.end_fill()# 画右边眼泪turtle.penup()turtle.goto(0, 0)turtle.setheading(0)turtle.left(90)turtle.fd(50)turtle.right(150)turtle.fd(150)turtle.left(150)turtle.fd(100)turtle.pendown()turtle.begin_fill()turtle.fd(-100)turtle.fillcolor("#7EB0C8") # tear colorturtle.right(60)turtle.circle(150, 15)turtle.left(45)turtle.fd(66)turtle.goto(77, 20)turtle.end_fill()# 画眼睛turtle.penup()turtle.pencolor("#6C4E00") # eye colorturtle.goto(-65, 75)turtle.setheading(0)turtle.left(27)turtle.fd(38)turtle.pendown()turtle.begin_fill()turtle.fillcolor("#6C4E00") # eye colorturtle.left(90)turtle.circle(38, 86)turtle.goto(position2[0], position2[1])turtle.goto(position1[0], position1[1])turtle.end_fill()# 画手turtle.pencolor("#D57E18") # hand side colorturtle.begin_fill()turtle.fillcolor("#EFBD3D") # hand color# 第一个手指arc(-110, 10, 110, -40, 30)turtle.circle(300, 35)turtle.circle(13, 120)turtle.setheading(-50)turtle.fd(20)turtle.setheading(130)# 第二个手指turtle.circle(200, 15)turtle.circle(12, 180)turtle.fd(40)turtle.setheading(137)# 第三个手指turtle.circle(200, 16)turtle.circle(12, 160)turtle.setheading(-35)turtle.fd(45)turtle.setheading(140)# 第四个手指turtle.circle(200, 13)turtle.circle(11, 160)turtle.setheading(-35)turtle.fd(40)turtle.setheading(145)# 第五个手指turtle.circle(200, 9)turtle.circle(10, 180)turtle.setheading(-31)turtle.fd(50)# 画最后手腕的部分turtle.setheading(-45)turtle.pensize(7)turtle.right(5)turtle.circle(180, 35)turtle.end_fill()turtle.begin_fill()turtle.setheading(-77)turtle.pensize(5)turtle.fd(50)turtle.left(-270)turtle.fd(7)turtle.pencolor("#EFBD3D")turtle.circle(30, 180)turtle.end_fill()turtle.done()
# ========牵着她的手,慢慢走下去============import turtleturtle.title('我想和你牵着手一直走下去')str = '我喜欢你NYL'turtle.speed(20) # 画笔速度turtle.setup(1800, 700, 70, 70)turtle.color('black', 'pink') # 画笔颜色turtle.pensize(3) # 画笔粗细turtle.hideturtle() # 隐藏画笔(先)turtle.up() # 提笔turtle.goto(-655, -255) # 移动画笔到指定起始坐标(窗口中心为0,0)turtle.down() # 下笔turtle.showturtle() # 显示画笔# ======画左边的小人=======turtle.goto(-600, -200)turtle.goto(-600, -120)turtle.circle(35)turtle.goto(-600, -200)turtle.forward(40)turtle.right(90)turtle.forward(60)turtle.hideturtle()turtle.up()turtle.goto(-600, -160)turtle.down()turtle.showturtle()turtle.left(90)turtle.forward(55)turtle.right(45)turtle.forward(20)turtle.hideturtle()turtle.up()turtle.goto(-600, -145)turtle.down()turtle.showturtle()turtle.goto(-545, -145)turtle.left(90)turtle.forward(20)# ========画第一个爱心==============turtle.color('red', 'red')turtle.begin_fill()turtle.hideturtle()turtle.up()turtle.goto(-500, -153)turtle.down()turtle.showturtle()turtle.right(90)turtle.forward(30)turtle.left(90)turtle.forward(30)turtle.left(45)turtle.circle(10.6, 180)turtle.left(180)turtle.circle(10.6, 180)turtle.end_fill()# =========下一个大爱心==============turtle.color('pink', 'red')turtle.begin_fill()turtle.hideturtle()turtle.up()turtle.goto(-430, -143)turtle.down()turtle.showturtle()turtle.left(135)turtle.right(90)turtle.forward(50)turtle.left(90)turtle.forward(50)turtle.left(45)turtle.circle(17.67, 180)turtle.left(180)turtle.circle(17.67, 180)turtle.end_fill()# ========第三个爱心=====================turtle.color('red', 'pink')turtle.begin_fill()turtle.hideturtle()turtle.up()turtle.goto(-315, -133)turtle.down()turtle.showturtle()turtle.left(135)turtle.right(90)turtle.forward(70)turtle.left(90)turtle.forward(70)turtle.left(45)turtle.circle(24.74, 180)turtle.left(180)turtle.circle(24.74, 180)turtle.end_fill()# ========第四个爱心===============turtle.color('red', 'pink')turtle.begin_fill()turtle.hideturtle()turtle.up()turtle.goto(-187, -133)turtle.down()turtle.showturtle()turtle.left(135)turtle.right(90)turtle.forward(70)turtle.left(90)turtle.forward(70)turtle.left(45)turtle.circle(24.74, 180)turtle.left(180)turtle.circle(24.74, 180)turtle.end_fill()# ========第5个爱心===============turtle.color('red', 'red')turtle.begin_fill()turtle.hideturtle()turtle.up()turtle.goto(-43.7, -143)turtle.down()turtle.showturtle()turtle.left(135)turtle.right(90)turtle.forward(50)turtle.left(90)turtle.forward(50)turtle.left(45)turtle.circle(17.67, 180)turtle.left(180)turtle.circle(17.67, 180)turtle.end_fill()# ==========第6个爱心==============turtle.color('red', 'pink')turtle.begin_fill()turtle.hideturtle()turtle.up()turtle.goto(53.88, -153)turtle.down()turtle.showturtle()turtle.right(90)turtle.right(225)turtle.forward(30)turtle.left(90)turtle.forward(30)turtle.left(45)turtle.circle(10.6, 180)turtle.left(180)turtle.circle(10.6, 180)turtle.end_fill()# =======画右边的小人==========turtle.hideturtle()turtle.up()turtle.goto(251.28, -255)turtle.down()turtle.showturtle()turtle.goto(196.28, -200)turtle.goto(196.28, -120)turtle.left(90)turtle.circle(35)turtle.goto(196.28, -200)turtle.left(180)turtle.forward(40)turtle.left(90)turtle.forward(60)turtle.hideturtle()turtle.up()turtle.goto(196.28, -160)turtle.down()turtle.showturtle()turtle.right(90)turtle.forward(55)turtle.left(45)turtle.forward(20)turtle.hideturtle()turtle.up()turtle.goto(196.28, -145)turtle.down()turtle.showturtle()turtle.right(45)turtle.forward(55)turtle.right(45)turtle.forward(20)# ==========画气球线和气球===============# ===第一个气球===turtle.hideturtle()turtle.up()turtle.goto(-265, -133)turtle.down()turtle.showturtle()turtle.goto(-245, 0)turtle.right(135)turtle.circle(35)# ===第2个气球===turtle.hideturtle()turtle.up()turtle.goto(-265, -133)turtle.down()turtle.showturtle()turtle.goto(-305, 80)turtle.circle(40)# ===第3个气球===turtle.hideturtle()turtle.up()turtle.goto(-137, -133)turtle.down()turtle.showturtle()turtle.goto(-167, 0)turtle.circle(35)# ===第4一个气球===turtle.hideturtle()turtle.up()turtle.goto(-137, -133)turtle.down()turtle.showturtle()turtle.goto(-117, 80)turtle.circle(40)# ===写字LOVE===turtle.pencolor("GREEN")turtle.penup()turtle.goto(-245, 10)turtle.write("O", move=False, align='center', font=("微软雅黑", 30, 'normal'))turtle.pencolor("PURPLE")turtle.penup()turtle.goto(-305, 90)turtle.write("L", move=False, align='center', font=("微软雅黑", 30, 'normal'))turtle.pencolor("YELLOW")turtle.penup()turtle.goto(-167, 10)turtle.write("V", move=False, align='center', font=("微软雅黑", 30, 'normal'))turtle.pencolor("ORANGE")turtle.penup()turtle.goto(-117, 90)turtle.write("E", move=False, align='center', font=("微软雅黑", 30, 'normal'))# ============写送给谁=============turtle.pencolor("PINK")turtle.penup()turtle.goto(300, 200)turtle.write(str, move=False, align='center', font=("方正舒体", 30, 'normal'))turtle.done()
来源地址:https://blog.csdn.net/weixin_45925028/article/details/132229895
--结束END--
本文标题: Python 十五个炫酷代码
本文链接: https://www.lsjlt.com/news/440549.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0