牛年快乐多媒体贺卡.py

如本文章标有价格,需议价或其它事情商议请加微信pythonxia

李兴球Python牛年快乐多媒体贺卡
"""
   牛年快乐多媒体贺卡.py
   本程序由Python海龟画图模块制作。
"""
import sys
import time
from turtle import *
from winsound import *
from bitmapfont import *
from winsound import PlaySound,SND_ASYNC,SND_LOOP

__author__ = '李兴球'
__date__ = '2021/2/8'

def xsleep(tm):
    """不断刷新屏幕等待一定的时间"""
    start = time.time()
    while time.time() - start < tm:
        screen.update()
        
def show_charactar(char,scale):
    """显示点阵汉字,返回宽高与坐标点"""
    alldots = []
    fontSet = open("./HZK16", "rb")
    arrays = getCharacterMatrixMode(fontSet, char)
    rows = len(arrays)
    cols = len(arrays[0])
    for row in range(rows):            # 每一行
        for col in range(cols):        # 每一列
            c = arrays[row][col]           
            if int(c):alldots.append([row*scale,col*scale])    
    height = rows * scale              # 字的高度
    width = cols * scale               # 字的宽度 
    return width,height,alldots

def display_chinese(char,c):
    """显示一个汉字,并且放在列表中"""
    w,h,zhong = show_charactar(char,10)
    # 求每个点应该呆的坐标,这样字刚好在屏幕中间
    cors = [[h//2-row,col-w//2] for row,col in zhong] 
    for cy,cx in cors:
        t = Turtle(visible=False,shape='circle')
        t.speed(0)
        t.penup()
        t.shapesize(0.5)
        t.goto(cx,cy)
        t.color('cyan',c)
        t.showturtle()
        time.sleep(0.01)
        
    xsleep(1)
    for t in screen.turtles():
        a = t.towards(0,0)
        t.setheading(a)
        t.right(180)
    c = 0
    while c < len(cors):
        for t in screen.turtles():
            if not t.isvisible():continue
            if t.distance(0,0)<350:
                t.fd(10)
            else:
                t.ht()
                c += 1

screen = Screen()
screen.setup(550,760)
screen.delay(0)
screen.colormode(255)
screen.bgcolor(0,0,0)

display_chinese('祝','black')
display_chinese('您','orange')
display_chinese('牛','yellow')
display_chinese('年','lime')
display_chinese('快','cyan')
display_chinese('乐','pink')

screen.bgcolor(254,0,0)
PlaySound('华语群星 - 恭喜发财+好日子+新年快乐+有钱没钱回家过年+年轻的朋友来相会.wav',SND_LOOP|SND_ASYNC)

frames = [f'ims/{i:04d}.png' for i in range(1,21)]
frames = [screen._image(im) for im in frames]
frames = [Shape('image',im) for im in frames]
[screen.addshape(str(i),frames[i]) for i in range(len(frames))]

denglong = Turtle(visible=False)
counter = 0
def alt_shape():
    global index,counter
    denglong.shape(str(index))
    index += 1
    index %= len(frames)
    if index==1 and counter>10:
        screen.ontimer(alt_shape,1000)
    else:
        screen.ontimer(alt_shape,100)
    counter += 1
index = 0
denglong.st()
alt_shape()

xsleep(2)
lixingqiu = Turtle(visible=False)
lixingqiu.penup()
lixingqiu.speed(0)
lixingqiu.goto(-120,300)
lixingqiu.color('white')
ft = ('楷体',30,'bold')
for char in '李兴球祝您':
    lixingqiu.write(char,font=ft)
    lixingqiu.fd(50)
    xsleep(0.3)
 
xsleep(2)
website = Turtle(visible=False)
website.penup()
website.speed(0)
website.goto(-110,250)
website.color('cyan')
ft = ('Arail',18,'normal')
for char in 'www.lixingqiu.com':
    website.write(char,font=ft)
    website.fd(14)
    xsleep(0.3)

f = open(sys.argv[0],encoding='utf-8')
content = f.read()
f.close()
codes = content.split('\n')
ct = Turtle(visible=False)
ct.penup()
ct.speed(0)
ct.color('#a7eff0')
ct.left(90)
number = 0
ft = ft = ('宋体',12,'normal')
def display_code():
    global number
    ct.clear()
    ct.goto(-200,-220)
    for j in range(10):
        code = codes[(number+j)%len(codes)]    
        ct.write(code,font=ft)
        ct.bk(18)
    number += 1
    number %= len(codes)        
    screen.ontimer(display_code,300)    
display_code()

erweimapic = '李兴球Python公众号半透明.png'
shape = Shape('image',screen._image(erweimapic))
screen.addshape('erweima',shape)

xsleep(1)
公众号 = Turtle(visible=False)
公众号.penup()
公众号.speed(0)
公众号.goto(200,-320)
公众号.shape('erweima')
公众号.st()

screen.mainloop() 

需要本程序所有源代码和素材请联系本人微信pythonxia

本站所有作品,教程等皆为原创,版权所有。只供个人及单位内部研究使用,对外展示或传播必需经本站同意,且注明来自本站。培训机构等用本站资源培训学生,需经本站授权。一旦付款,表示同意本站知识付费原则:数字商品,不支持退款。亦可直接向微信号scratch8付款购买。入住QQ群:225792826 和爱好者共同交流,并且能下载免费提供的Python资源(需提供真实姓名才可入群)
李兴球的博客_Python创意编程技术前沿_pygame » 牛年快乐多媒体贺卡.py
scratch

学本领,探索更大的世界!

李兴球博客 风火轮编程主页