def main(): graphics_dict, screen = initialize() pygame.font.init() font_object = pygame.font.Font('freesansbold.ttf', 50) text_object = font_object.render('Test', False, (255, 255, 0)) screen.blit(text_object, (100, 100)) pygame.display.flip() x = 100 while True: # time_to_move = next(cool_down_number()) # print(time_to_move) text_object = font_object.render('Rap', False, (255, 255, 0)) screen.blit(text_object, (x, 200)) x += 100 pygame.display.flip() pygame.time.delay(500)
interpret(subtrees) graphics.endtag() elif nodetype == "javascript-element": jstext = node[1] jslexer = lex.lex(module=jstokens) jsparser = yacc.yacc(module=jsgrammar) jstree = jsparser.parse(jstext, lexer=jslexer) result = jsinterp.interpret(jstree) graphics.word(result) ## if False: ## print jstext ## jslexer.input(jstext) ## while True: ## tok = jslexer.token() ## if not tok: break ## print tok jsparser = yacc.yacc(module=jsgrammar, tabmodule="parsetabjs") jsast = jsparser.parse(jstext, lexer=jslexer) result = jsinterp.interpret(jsast) graphics.word(result) ## WHAT'S HERE? # Note that graphics.initialize and finalize will only work surrounding a call # to interpret graphics.initialize() # Enables display of output.\ interpret([("word-element", "Hello")]) graphics.finalize() # Enables display of output.
</p> <hr> </hr> <!-- draw a horizontal bar --> <p> Now we will use JavaScript to display even numbers in <i>italics</i> and odd numbers in <b>bold</b>. <br> </br> <script type="text/javascript"> function tricky(i) { if (i <= 0) { return i; } ; if ((i % 2) == 1) { write("<b>"); write(i); write("</b>"); } else { write("<i>"); write(i); write("</i>"); } return tricky(i - 1); } tricky(10); </script> </p> </html>""" htmlast = htmlparser.parse(webpage,lexer=htmllexer) graphics.initialize() # let's start rendering a webpage interpret(htmlast) graphics.finalize() # we're done rendering this webpage
</p> <hr> </hr> <!-- draw a horizontal bar --> <p> Now we will use JavaScript to display even numbers in <i>italics</i> and odd numbers in <b>bold</b>. <br> </br> <script type="text/javascript"> function tricky(i) { if (i <= 0) { return i; } ; if ((i % 2) == 1) { write("<b>"); write(i); write("</b>"); } else { write("<i>"); write(i); write("</i>"); } return tricky(i - 1); } tricky(10); </script> </p> </html>""" htmlast = htmlparser.parse(webpage, lexer=htmllexer) graphics.initialize() # let's start rendering a webpage interpret(htmlast) graphics.finalize() # we're done rendering this webpage
import graphics graphics.initialize() graphics.begintag(tagname, tagargs) interpret(subtrees) graphics.endtag()
# web browser is not as "forgiving" as commercial browsers, but it is still # possible to make interesting webpages with it. Use your creativity! webpage = """<html> Put something here. You must include embedded JavaScript for full credit, but beyond that, do whatever you like. <script type="text/javascript">write("In Javascript Land");</script> <b>After javascript land</b> </html> """ import ply.lex as lex import ply.yacc as yacc import htmltokens import htmlgrammar import htmlinterp import graphics as graphics import jstokens htmllexer = lex.lex(module=htmltokens) htmlparser = yacc.yacc(module=htmlgrammar,tabmodule="parsetabhtml") ast = htmlparser.parse(webpage,lexer=htmllexer) jslexer = lex.lex(module=jstokens) graphics.initialize() # Enables display of output. htmlinterp.interpret(ast) graphics.finalize() # Enables display of output. # We would also like to take this opportunity to thank everyone in Udacity for # their support in making this class happen, especially those behind the scenes. # Check out team.jpeg for a group photo!
self.f.seek(offset, whence) return self.f.tell() def queue(filename): global song_info, player, data_queue, thread_queue yield Song(filename) if __name__ == '__main__': parser = argparse.ArgumentParser(description='Process a sound file.') parser.add_argument('filename', type=str, help='the path to the sound file') parser.add_argument('-d', dest='duration', type=float, help='specify the duration of the sound file to be analyzed') args = parser.parse_args() framerate = 0.1 # change this to adjust video and audio analysis fr data_queue = Queue() song_info = gather_data(args.filename) player = musicplayer.createPlayer() sphere = Sphere(100, 100) graphics.initialize(player, sphere, **song_info) graphics.setup() raw_input("Analysis complete. Press Enter to continue...\n") player.queue = queue(args.filename) player.playing = True graphics.run()
import ply.lex as lex import ply.yacc as yacc import htmltokens import htmlgrammar import htmlinterp import graphics htmllexer = lex.lex(module=htmltokens) htmlparser = yacc.yacc(module=htmlgrammar, tabmodule="parsetabhtml") f = open("37_factorial.html") contents = f.read() parse_tree = htmlparser.parse(contents, lexer=htmllexer) graphics.initialize() htmlinterp.interpret(parse_tree) graphics.finalize()
import pygame import thorpy import parameters as p import graphics, menus, gamelogic, ship if __name__ == "__main__": try: pygame.mixer.pre_init(44100, -16, 1, 512) except: print("Could not preinitialize pygame mixer.") pygame.init() app = thorpy.Application((p.W, p.H), "The Rule") menus.mainmenu() menus.choose_name() loadbar = graphics.initialize() ship.initialize_meshes(loadbar) gamelogic.play_carreer(nmissions=6, starting_mission=0) app.quit()