本文最后更新于47 天前,其中的信息可能已经过时,如有错误请发送邮件到1360078335@qq.com
文件地址
https://github.com/xiaohaowen21/bless
这是一个用python写的文字性展示代码,是一段祝福语。
有能力的去上面这个地址去CODE代码。那个的可读性高一些。
这里再放一个代码
& "C:\Users\13600\AppData\Local\Programs\Python\Python313\python.exe" -c "import pygame;import sys;import random;import math;import time;WIDTH,HEIGHT=1200,800;FPS=60;TEXT_DISPLAY_DURATION=4;FADE_DURATION=1.5;PARTICLE_COUNT_PER_TEXT=150;FIREWORK_COUNT=10;FIREWORK_MIN_DELAY=1;FIREWORK_MAX_DELAY=2;BLACK=(0,0,0);WHITE=(255,255,255);TEXT_COLORS=[(255,105,180),(138,43,226),(0,191,255),(255,215,0),(50,205,50),(255,99,71)];FONT_PATH='simkai.ttf';FONT_SIZE=60;FINAL_TEXT_FONT_SIZE=80;class Particle: def __init__(self,x,y,color,speed_min=1,speed_max=5,lifetime=200): self.x=x;self.y=y;self.color=color;self.velocity_x=random.uniform(-speed_max,speed_max);self.velocity_y=random.uniform(-speed_max,speed_max);self.lifetime=lifetime;self.age=0;self.size=random.randint(2,5); def update(self): self.x+=self.velocity_x;self.y+=self.velocity_y;self.age+=1;self.velocity_y+=0.1;self.size=max(0,self.size-0.05); def draw(self,screen): alpha=max(0,255-int(self.age*255/self.lifetime));surface=pygame.Surface((self.size*2,self.size*2),pygame.SRCALPHA);pygame.draw.circle(surface,(*self.color,alpha),(self.size,self.size),self.size);screen.blit(surface,(self.x-self.size,self.y-self.size)); def is_dead(self): return self.age>=self.lifetime or self.size<=0;class ParticleSystem: def __init__(self): self.particles=[]; def emit_particles(self,x,y,count,color,speed_min=1,speed_max=5,lifetime=100): for _ in range(count): self.particles.append(Particle(x,y,color,speed_min,speed_max,lifetime)); def update(self): self.particles=[p for p in self.particles if not p.is_dead()]; for p in self.particles: p.update(); def draw(self,screen): for p in self.particles: p.draw(screen);class Firework: def __init__(self): self.rockets=[];self.explosions=[];self.next_firework_time=time.time()+random.uniform(FIREWORK_MIN_DELAY,FIREWORK_MAX_DELAY); def launch_rocket(self): start_x=random.randint(WIDTH//4,WIDTH*3//4);start_y=HEIGHT;target_x=start_x+random.randint(-WIDTH//8,WIDTH//8);target_y=random.randint(HEIGHT//5,HEIGHT//2);color=(random.randint(100,255),random.randint(100,255),random.randint(100,255));self.rockets.append({'x':start_x,'y':start_y,'target_x':target_x,'target_y':target_y,'color':color,'speed':random.uniform(5,10),'exploded':False}); def update(self): if time.time()>=self.next_firework_time and len(self.rockets)<FIREWORK_COUNT/2: self.launch_rocket();self.next_firework_time=time.time()+random.uniform(FIREWORK_MIN_DELAY,FIREWORK_MAX_DELAY); for rocket in self.rockets[:]: if not rocket['exploded']: rocket['y']-=rocket['speed'];rocket['x']+=(rocket['target_x']-rocket['x'])*0.05; if rocket['y']<=rocket['target_y']: rocket['exploded']=True;self.explode(rocket['x'],rocket['y'],rocket['color']);self.rockets.remove(rocket); for explosion in self.explosions[:]: explosion['age']+=1; if explosion['age']>explosion['lifetime']: self.explosions.remove(explosion); else: for particle in explosion['particles']: particle.update(); def explode(self,x,y,color): explosion_particles=[];num_particles=random.randint(80,150);base_speed=random.uniform(2,5); for _ in range(num_particles): angle=random.uniform(0,2*math.pi);speed_mult=random.uniform(0.5,1.5);particle_color=(min(255,color[0]+random.randint(-50,50)),min(255,color[1]+random.randint(-50,50)),min(255,color[2]+random.randint(-50,50)));explosion_particles.append(Particle(x,y,particle_color,speed_min=base_speed*speed_mult*0.8,speed_max=base_speed*speed_mult*1.2,lifetime=random.randint(60,100))); self.explosions.append({'x':x,'y':y,'color':color,'particles':explosion_particles,'age':0,'lifetime':150}); def draw(self,screen): for rocket in self.rockets: if not rocket['exploded']: pygame.draw.circle(screen,rocket['color'],(int(rocket['x']),int(rocket['y'])),3); for explosion in self.explosions: for particle in explosion['particles']: particle.draw(screen);def main(): pygame.init();screen=pygame.display.set_mode((WIDTH,HEIGHT));pygame.display.set_caption('向阳而生');clock=pygame.time.Clock(); try: font=pygame.font.Font(FONT_PATH,FONT_SIZE);final_font=pygame.font.Font(FONT_PATH,FINAL_TEXT_FONT_SIZE); except FileNotFoundError: print(f'错误: 找不到字体文件 "{FONT_PATH}"。请确保文件在代码同目录下。');print('您可以在网上搜索 "行楷字体下载" 来获取一个 .ttf 字体文件。');pygame.quit();sys.exit(); phrases=['今天怎么样,朋友,你还好吗。','童话故事里的故事不是每个人都会遇到,但是,我们要知道。','人生没有白走的路,每一步都会算数。','如果错过了落日余晖,就别再错过满天繁星。','你总会遇到那束,属于你的曙光。']; current_phrase_index=0;start_time=time.time();current_text_alpha=0;fading_in=True;displaying_text=True;particles=ParticleSystem();fireworks=Firework();show_final_text=False;final_text_alpha=0; running=True; while running: for event in pygame.event.get(): if event.type==pygame.QUIT: running=False; if event.type==pygame.KEYDOWN: if event.key==pygame.K_ESCAPE: running=False; screen.fill(BLACK); if displaying_text: elapsed_time=time.time()-start_time; if fading_in: current_text_alpha=min(255,int(255*(elapsed_time/FADE_DURATION))); if elapsed_time>=FADE_DURATION: fading_in=False;start_time=time.time(); else: if elapsed_time<TEXT_DISPLAY_DURATION: pass; else: fade_out_elapsed=elapsed_time-TEXT_DISPLAY_DURATION;current_text_alpha=max(0,255-int(255*(fade_out_elapsed/FADE_DURATION))); if current_text_alpha==0: current_phrase_index+=1; if current_phrase_index<len(phrases): start_time=time.time();fading_in=True;particles.particles=[];rendered_text=font.render(phrases[current_phrase_index-1],True,TEXT_COLORS[current_phrase_index%len(TEXT_COLORS)]);text_rect=rendered_text.get_rect(center=(WIDTH//2,HEIGHT//2));particles.emit_particles(text_rect.centerx,text_rect.centery,PARTICLE_COUNT_PER_TEXT,random.choice(TEXT_COLORS),speed_min=0.5,speed_max=3,lifetime=150); else: displaying_text=False;particles.particles=[]; if current_phrase_index<len(phrases): text_color=TEXT_COLORS[current_phrase_index%len(TEXT_COLORS)];text_surface=font.render(phrases[current_phrase_index],True,text_color);text_with_alpha=pygame.Surface(text_surface.get_size(),pygame.SRCALPHA);text_with_alpha.blit(text_surface,(0,0));text_with_alpha.set_alpha(current_text_alpha);text_rect=text_with_alpha.get_rect(center=(WIDTH//2,HEIGHT//2));screen.blit(text_with_alpha,text_rect); if fading_in and current_text_alpha>0 and current_text_alpha%20==0: for _ in range(3): rand_x=random.randint(text_rect.left,text_rect.right);rand_y=random.randint(text_rect.top,text_rect.bottom);particles.emit_particles(rand_x,rand_y,1,random.choice(TEXT_COLORS),speed_min=0.5,speed_max=2,lifetime=60); else: if len(particles.particles)==0: if not show_final_text: fireworks.update();fireworks.draw(screen); if time.time()-start_time>5 and len(fireworks.rockets)==0 and len(fireworks.explosions)==0: show_final_text=True;start_time=time.time(); else: if not show_final_text: fireworks.update();fireworks.draw(screen); if time.time()-start_time>FIREWORK_COUNT*(FIREWORK_MAX_DELAY+0.5) or (len(fireworks.rockets)==0 and len(fireworks.explosions)==0 and fireworks.next_firework_time<time.time()): show_final_text=True;start_time=time.time(); else: elapsed_fade=time.time()-start_time;final_text_alpha=min(255,int(255*(elapsed_fade/FADE_DURATION/2)));final_text_surface=final_font.render('向阳而生',True,WHITE);final_text_with_alpha=pygame.Surface(final_text_surface.get_size(),pygame.SRCALPHA);final_text_with_alpha.blit(final_text_surface,(0,0));final_text_with_alpha.set_alpha(final_text_alpha);final_text_rect=final_text_with_alpha.get_rect(center=(WIDTH//2,HEIGHT//2));screen.blit(final_text_with_alpha,final_text_rect); particles.update();particles.draw(screen); pygame.display.flip();clock.tick(FPS); pygame.quit();sys.exit();if __name__=='__main__': main()"
这个的可读性太低了,但是好在可以直接复制粘贴使用。想让代码跑起来需要安装Pygame库,也需要Python(这个是基础)。字体文件可以自己去网上下载,要找那种 .ttf 结尾的文件格式。同时将字体文件和代码文件放进同一个文件夹里。字体文件重命名为simkai.ttf
接下来就可以运行了。