猫史档案馆


【Python作品分享】欢欢喜喜介绍函-南宁市第二中学初中部-陈凤-1897880

用户:mengOuMimengOuMi查看:0 回复:1 评论:0 创建时间:2021-05-13T11:06:26


【作品展示】

center_image

 

【作品介绍】

展示广西名族风采,欢迎友人到来,制作这个介绍涵

 

【作品源代码】

#生成两张词云图
import jieba
import matplotlib
import wordcloud
import imageio
import pygame 
pygame.init()
pygame.mixer.init()
pygame.mixer.music.set_volume(0.2)
pygame.mixer.music.load('民歌.mp3')
mk1 = imageio.imread('欢欢p.png')
mk2 = imageio.imread('喜喜p.png')
wc1 = wordcloud.WordCloud(mask=mk1,background_color='white', font_path='simhei.ttf')
wc2 = wordcloud.WordCloud(mask=mk2,background_color='white', font_path='simhei.ttf')
txt = open("欢欢.txt",'r',encoding='utf-8').read()
txt = jieba.lcut(txt)
txt = ' '.join(txt)
wc1.generate(txt)
wc2.generate(txt)
wc1.to_file('hhc.png')
wc2.to_file('xxc.png')
#制作游戏窗口
size=width,height=800,600
screen=pygame.display.set_mode(size)
pygame.display.set_caption("欢欢喜喜介绍函")
hh=pygame.image.load('欢欢p.png')
xx = pygame.image.load('喜喜p.png')
hhc = pygame.image.load('hhc.png')
xxc = pygame.image.load('xxc.png')
x1=0
x2=600
y1=200
y2=170

font1=pygame.font.SysFont(None,40)
font2 = pygame.font.SysFont('simhei', 50)
font3 = pygame.font.SysFont('simhei', 30)
font4 = pygame.font.SysFont('simhei', 30)
font5 = pygame.font.SysFont('simhei', 15)
font6 = pygame.font.SysFont('simhei', 30)
w1 = font1.render('Gvangisih Bouxcuengh Swcigih 1958', 1, (200,0,0))
w2 = font2.render('广西壮族自治区', 1, (200, 0, 0))
w3 = font3.render('欢欢', 1, (0, 0, 0))
w4 = font4.render('喜喜', 1, (0, 0, 0))
w5 = font5.render('想要更详细地了解我们吗?点我吧', 1, (200, 0, 0))
w6 = font6.render('广西欢迎您', 1, (200, 0, 0))
y3 = 700
y4=700
x5=800
mouse_x,mouse_y=pygame.mouse.get_pos()
num=0
pygame.mixer.init()
pygame.mixer.music.set_volume(0.2)
pygame.mixer.music.load('民歌.mp3')
pygame.mixer.music.play()
while True:
    for event in pygame.event.get():     
        if event.type==pygame.QUIT:
            sys.exit()
        elif event.type==pygame.MOUSEBUTTONDOWN:
            mouse_x,mouse_y = event.pos
            if event.button==1 and (mouse_x > 200 and mouse_x < 570 and mouse_y > 170 and mouse_y < 400):
                num += 1
                #print(111)
    if num==0:
        screen.fill((255,255,255))
        screen.blit(hh, (x1, y1))
        screen.blit(xx, (x2, y2))
        x1=x1+2
        if x1>200:
            x1=200
        #print("a")
        #screen.blit(xx, (x2, y2))
        x2 = x2-2
        y2=y2+0.4
        if x2 < 400:
            x2 = 400
            y2=210
        screen. blit(w1,(100,100))
        screen. blit(w2, (200, 40))
        screen. blit(w3, (250, y3))
        screen. blit(w4, (479, y4))
        screen. blit(w5, (x5, 150))
        y3=y3-1
        y4=y4-1
        if y3<500:
            y3=500
        if y4 < 500:
            y4 = 500
            x5=x5-3
        if x5 < 130:
            x5 = 130
        
    elif num >= 1:
        screen.fill((255, 255, 255))
        #重置坐标
        if(num==1):
            x1 = 0
            x2 = 600
            y1 = 200
            y2 = 170
            num += 1
        screen.blit(hhc, (x1, y1))
        screen.blit(xxc, (x2, y2))
        screen. blit(w1, (100, 100))
        screen. blit(w2, (200, 40))
        screen. blit(w3, (250, y3))
        screen. blit(w4, (470, y4))
        screen. blit(w6, (250, 140))
        x1 = x1+2
        if x1 > 200:
            x1 = 200
        #screen.blit(xxc, (x2, y2))
        x2 = x2-2
        y2 = y2+0.4
        if x2 < 400:
            x2 = 400
            y2 = 210
            y3 = y3-1
            y4 = y4-1
        if y3 < 500:
            y3 = 500
        if y4 < 500:
            y4 = 500
            x5 = x5-3
        if x5 < 130:
            x5 = 130
    pygame.display.update()
    pygame.time.delay(15) 
#创建字体对象,绘制字体

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 1下一页
活力飓风雀活力飓风雀

来顶一下

点赞0


评论