520專屬Python程式碼分享

Python小二發表於2022-05-22

快到 520 了,分享幾段 520 專屬 Python 程式碼,不多說了,下面直接上貨。

No.1

效果:

主要程式碼:

import turtle

turtle.speed(0)
turtle.delay(10)
turtle.penup()
turtle.left(90)
turtle.fd(200)
turtle.pendown()
turtle.right(90)
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.left(150)
turtle.circle(-90, 70)
turtle.left(20)
turtle.circle(75, 105)
turtle.setheading(60)
turtle.circle(80, 98)
turtle.circle(-90, 40)
# 文字
turtle.color('red')
turtle.pu()
turtle.goto(-210,80)
turtle.pd()
turtle.write('520 Happy', move=False, align='center',font=("Times", 18, "bold"))
turtle.pu()
turtle.goto(210,80)
turtle.pd()
turtle.write('I LOVE YOU', move=False, align='center',font=("Times", 18, "bold"))
turtle.pu()
turtle.pu()
turtle.hideturtle()
turtle.done()

No.2

效果:

主要程式碼:

import turtle as t

t.speed(0)
t.delay(10)
t.color('red','pink')
t.begin_fill()
t.width(5)
t.left(135)
t.fd(100)
t.right(180)
t.circle(50,-180)
t.left(90)
t.circle(50,-180)
t.right(180)
t.fd(100)
t.pu()
t.goto(50,-30)
# 箭頭
t.begin_fill()
t.left(-30)
t.fd(-15)
t.right(-40)
t.fd(-50)
t.right(-165)
t.fd(-50)
t.end_fill()
# 文字
t.color('red')
t.pu()
t.goto(-150,30)
t.pd()
t.write('I LOVE YOU',
move=False, align='center',
font=("Times", 18, "bold"))
t.hideturtle()
t.done()

No.3

效果:

主要程式碼:

import turtle
import random

# 畫愛心
def love(x, y):
    lv = turtle.Turtle()
    lv.hideturtle()
    lv.up()
    # 定位
    lv.goto(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)
    lv.down()
    lv.begin_fill()
    lv.left(140)
    lv.forward(22)
    curvemove()
    lv.left(120)
    curvemove()
    lv.forward(22)
    # 畫完復位
    lv.left(140)
    lv.end_fill()
myWin = turtle.Screen()
myWin.setup(width=700, height=700)
t = turtle.Turtle()
t.speed(0)
turtle.delay(0)
t.hideturtle()
t.left(90)
t.up()
t.backward(200)
t.down()
t.color("brown")
t.pensize(32)
t.forward(60)
tree(100, t)
myWin.exitonclick()    

原始碼在公眾號Python小二後臺回覆py520獲取~

相關文章