Vertically Scrolling Text on Python
What’s not to like about vertically scrolling text? Its uses are many: the beginning of a game or introduction to something epic, like the beginning of every Star Wars movie; a list of credits at the end of something, such as a Python presentation. The list goes on.
Vertically Scrolling Text on Python |
EPICSCROLL.PY
We’ve used the poem Cimmeria by Robert E. Howard for the code’s scrolling text, along with a dramatic black background and red text. We think you’ll agree, it’s quite epic.
import pygame as pg from pygame.locals import * pg.init() text _ list = ‘’’ I remember The dark woods, masking slopes of sombre hills; The grey clouds’ leaden everlasting arch; The dusky streams that flowed without a sound, And the lone winds that whispered down the passes. Vista on vista marching, hills on hills, Slope beyond slope, each dark with sullen trees, Our gaunt land lay. So when a man climbed up A rugged peak and gazed, his shaded eye Saw but the endless vista – hill on hill, Slope beyond slope, each hooded like its brothers. It was a gloomy land that seemed to hold All winds and clouds and dreams that shun the sun, With bare boughs rattling in the lonesome winds, And the dark woodlands brooding over all, Not even lightened by the rare dim sun Which made squat shadows out of men; they called it Cimmeria, land of Darkness and deep Night. It was so long ago and far away I have forgot the very name men called me. The axe and flint-tipped spear are like a dream, And hunts and wars are shadows. I recall Only the stillness of that sombre land; The clouds that piled forever on the hills, The dimness of the everlasting woods. Cimmeria, land of Darkness and the Night. Oh, soul of mine, born out of shadowed hills, To clouds and winds and ghosts that shun the sun, How many deaths shall serve to break at last This heritage which wraps me in the grey Apparel of ghosts? I search my heart and find Cimmeria, land of Darkness and the Night! ‘’’.split(‘\n’) class Credits: def _ _ init _ _ (self, screen _ rect, lst): self.srect = screen _ rect self.lst = lst self.size = 16 self.color = (255,0,0) self.buff _ centery = self.srect.height/2 + 5 self.buff _ lines = 50 self.timer = 0.0 self.delay = 0 self.make _ surfaces() def make _ text(self,message): font = pg.font.SysFont(‘Arial’, self.size) text = font.render(message,True,self.color) rect = text.get _ rect(center = (self.srect. centerx, self.srect.centery + self.buff _ centery) ) return text,rect def make _ surfaces(self): self.text = [] for i, line in enumerate(self.lst): l = self.make _ text(line) l[1].y += i*self.buff _ lines self.text.append(l) def update(self): if pg.time.get _ ticks()-self.timer > self.delay: self.timer = pg.time.get _ ticks() for text, rect in self.text: rect.y -= 1 def render(self, surf): for text, rect in self.text: surf.blit(text, rect) screen = pg.display.set _ mode((800,600)) screen _ rect = screen.get _ rect() clock = pg.time.Clock() running=True cred = Credits(screen _ rect, text _ list) while running: for event in pg.event.get(): if event.type == QUIT: running = False screen.fill((0,0,0)) cred.update() cred.render(screen) pg.display.update() clock.tick(60)
0 Response to "Vertically Scrolling Text on Python"
Post a Comment