
520即將來襲~普通人表白,發微信買花
程式員表白,用代碼給女神畫玫瑰,畫愛心無線彈窗表白,網頁無線彈窗表白
第一種:心連心

from turtle import*
color ("black","red")
pensize(5)
begin_fill()
penup()
goto(50,50)
pendown()
right(45)
goto(100,0)
left(90)
fd(120)
circle(50,225)
penup()
goto(0,0)
pendown()
left(135)
fd(120)
circle(50,225)
seth(90)
circle(50,225)
fd(121)
end_fill()
left(56)
penup()
goto(-210,40)
pendown()
goto(0,80)
penup()
goto(160,110)
pendown()
goto(320,140)
done()
更多關注公眾號:學習py最風sao的方式
第二種:玫瑰花

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()

第三種:畫彩虹
所有美好的事情都是彩虹

from turtle import *
def HSB2RGB(hues):
hues = hues * 3.59 #100轉成359范圍
rgb=[0.0,0.0,0.0]
i = int(hues/60)%6
f = hues/60 -i
if i == 0:
rgb[0] = 1; rgb[1] = f; rgb[2] = 0
elif i == 1:
rgb[0] = 1-f; rgb[1] = 1; rgb[2] = 0
elif i == 2:
rgb[0] = 0; rgb[1] = 1; rgb[2] = f
elif i == 3:
rgb[0] = 0; rgb[1] = 1-f; rgb[2] = 1
elif i == 4:
rgb[0] = f; rgb[1] = 0; rgb[2] = 1
elif i == 5:
rgb[0] = 1; rgb[1] = 0; rgb[2] = 1-f
return rgb
def rainbow():
hues = 0.0
color(1,0,0)
#繪制彩虹
hideturtle()
speed(100)
pensize(3)
penup()
goto(-400,-300)
pendown()
right(110)
for i in range (100):
circle(1000)
right(0.13)
hues = hues + 1
rgb = HSB2RGB(hues)
color(rgb[0],rgb[1],rgb[2])
penup()
def main():
setup(800, 600, 0, 0)
bgcolor((0.8, 0.8, 1.0))
tracer(False)
rainbow()
#輸出文字
tracer(False)
goto(100,-100)
pendown()
color("red")
tracer(True)
mainloop()
if __name__ == "__main__":
main()
第四種:愛心—送給所有的小仙女

原始碼:
# -*- coding:utf-8 -*-
import turtle
import time
# 畫愛心的頂部
def LittleHeart():
for i in range(200):
turtle.right(1)
turtle.forward(2)
# 輸入表白的陳述句,默認I Love you
love = input('請輸入表白陳述句,默認為輸入為"I Love you": ')
# 輸入署名或者贈誰,沒有不執行
me = input('請輸入您心上人的姓名或者昵稱: ')
if love == '':
love = 'I Love you'
# 視窗大小
turtle.setup(width=800, height=500)
# 顏色
turtle.color('red', 'pink')
# 筆粗細
turtle.pensize(5)
# 速度
turtle.speed(1)
# 提筆
turtle.up()
# 隱藏筆
turtle.hideturtle()
# 去到的坐標,視窗中心為0,0
turtle.goto(0, -180)
turtle.showturtle()
# 畫上線
turtle.down()
turtle.speed(1)
turtle.begin_fill()
turtle.left(140)
turtle.forward(224)
# 呼叫畫愛心左邊的頂部
LittleHeart()
# 呼叫畫愛右邊的頂部
turtle.left(120)
LittleHeart()
# 畫下線
turtle.forward(224)
turtle.end_fill()
turtle.pensize(5)
turtle.up()
turtle.hideturtle()
# 在心中寫字 一次
turtle.goto(0, 0)
turtle.showturtle()
turtle.color('#CD5C5C', 'pink')
# 在心中寫字 font可以設定字體自己電腦有的都可以設 align開始寫字的位置
turtle.write(love, font=('gungsuh', 30,), align="center")
turtle.up()
turtle.hideturtle()
time.sleep(2)
# 在心中寫字 二次
turtle.goto(0, 0)
turtle.showturtle()
turtle.color('red', 'pink')
turtle.write(love, font=('gungsuh', 30,), align="center")
turtle.up()
turtle.hideturtle()
# 寫署名
if me != '':
turtle.color('black', 'pink')
time.sleep(2)
turtle.goto(180, -180)
turtle.showturtle()
turtle.write(me, font=(20,), align="center", move=True)
# 點擊視窗關閉
window = turtle.Screen()
window.exitonclick()
、、


轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/281272.html
標籤:python
上一篇:python可視化圖表生成(一)
