新年了,用python编程设计有意义背景图片的一朵玫瑰花给心爱的人吧
在网上有很多画玫瑰的程序,可以放入pytharm中运行。我探索改进了一下,觉得做得可以个性化一点,这样送人玫瑰显得更有诚意。也为自己入门编程增添一些信心与乐趣。
先看一下效果:https://p.qpic.cn/vpic/0/e3217ntjq4y_fast_5.jpg/0
为了这么点东西,用到几个软件:1、pycharm编程;2、PS制作成动态图;3、camtasia录屏;4、爱剪辑配乐;5、绘影字幕添字幕。
-- coding: utf-8 --
import turtle
def bgpic(self, picname=None):
“”"Set background image or return name of current backgroundimage.
Optional argument:
picname -- a string, name of a gif-file or "nopic".
If picname is a filename, set the corresponding image as background.
If picname is "nopic", delete backgroundimage, if present.
If picname is None, return the filename of the current backgroundimage.
Example (for a TurtleScreen instance named screen):
>>> screen.bgpic()
'nopic'
>>> screen.bgpic("landscape.gif")
>>> screen.bgpic()
'landscape.gif'
"""
if picname is None:
return self._bgpicname
if picname not in self._bgpics:
self._bgpics[picname] = self._image(picname)
self._setbgpic(self._bgpic, self._bgpics[picname])
self._bgpicname = picname
if name == ‘main’:
myWin = turtle.Screen()
turtle.setup(width=1600, height=1750, startx=0, starty=0)
turtle.screensize(800,600)
turtle.bgpic(‘D:/softwarespace/python/玫瑰设计/1.gif’) # 这样设置,注意:1、单引号里面的是您的图片所存放的路径;2、是“/”不是"",容易搞错;3、用PS转化一下图片格式,导入到这里的时候也就显示GIF中的第一帧图片。
from turtle import *
import time
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()
color(“yellow”) # 指定字体为蓝色;自加段落
write(“一声新年好”, move=False, align=“right”, font=(“楷体”, 40,“normal”))
color(“black”)
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)
import turtle #自加段落
color(“yellow”) #指定打出的字为蓝色
write(“揭开新年的面罩”, move=False, align=“right”, font=(“楷体”, 40, “normal”))
color(“black”) #最后的指标为黑色
myWin.exitonclick()