How to use pygame to make animated racing lantern in Python
In this issue, the editor will bring you about how to use pygame to make animated racing lanterns in Python. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.
Import pygamefrom random import randint, choicescreen_length = 700screen_width = 50mm simulation ribbon falling class Falling words as ribbon class Word_drop (pygame.sprite.Sprite): # setting properties: including font, falling speed, ribbon source, ribbon frame properties def _ _ init__ (self): pygame.sprite.Sprite.__init__ (self) self.font = pygame.font.SysFont (name='', size=10, bold=True, italic=True) self.speed = randint (15 30) self.word = self.getWord () self.image = self.font.render (self.word, True, (randint (0255), randint (0255), randint (0255)) self.image = pygame.transform.rotate (self.image, randint (87) 93) self.rect = self.image.get_rect () self.rect.topleft = (randint (0, screen_length),-20) # get the dropped word def getWord (self): length = randint (1) 8) word =''for i in range (length): word + = choice (' qwertyuiopasdfghjklzxcvbnm1234567890QWERTYUIOPASDFGHJKLZXCVBNM') return word # set the condition for ribbon update def update (self, * args): self.rect = self.rect.move (0 Self.speed) if self.rect.top > screen_length: self.kill () # def word_translate (jx, ztw1, ztw2, screen_length, text): max_ztw = max (ztw1, ztw2) jx.x-= 5 if jx.x
< 0 - max_ztw: jx.x = (screen_length + 10) screen.blit(text, [jx.x, jx.y])if __name__ == '__main__': # 初始化工作 pygame.init() pygame.font.init() # 渲染字体,两行字 a = pygame.font.SysFont(name='幼圆', size=50, bold=True, italic=True) word1 = ">The above is the editor for you to share the Python how to use pygame to make animation racing lantern, if you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.