def proc_keys(): global music_on, laser_on, radius # if a 'c' key is pressed clear drawing window if pythonGraph.key_pressed('c'): # erase window pythonGraph.clear_window(pythonGraph.colors.BLACK) # if a 'p' is press key toggle play music or if music is on turn it off if pythonGraph.key_pressed('p'): if not music_on: pythonGraph.play_music('my_music.mp3') else: pythonGraph.stop_music() music_on = not music_on # if a 's' is pressed to toggle laser sound on draw - when you draw a laser sound effect # is played if pythonGraph.key_pressed('s'): pythonGraph.play_sound_effect('laser.wav') laser_on = not laser_on # if the 'escape' or 'q' key is pressed exit if pythonGraph.key_pressed('escape') or pythonGraph.key_pressed('q'): pythonGraph.close_window() # if 'up' or 'down' is pressed increase or decrese size of pen if pythonGraph.key_pressed('up'): radius += 3 if pythonGraph.key_pressed('down') and radius >= 3: radius -= 3
def config(): # setup pythonGraph.open_window(700, 700) pythonGraph.clear_window(pythonGraph.colors.BLACK) pythonGraph.set_window_title('PythonGraph Draw')
def erase_everything(): pythonGraph.clear_window(pythonGraph.colors.WHITE)
""" lsn13_examples_3of4.py - example code from lesson 13 """ __author__ = "CS110Z" import pythonGraph, random # setup pythonGraph.open_window(700, 700) while pythonGraph.window_not_closed(): # draw a circle at the random corrodinates pythonGraph.draw_circle(random.randint(0, 699), random.randint(0, 699), random.randint(10, 70), pythonGraph.create_random_color(), True) # if the 's' key is pressed stop the music if pythonGraph.key_pressed('s'): pythonGraph.stop_music() # if 'p' key is pressed play some background music if pythonGraph.key_pressed('p'): pythonGraph.play_music('my_music.mp3') # if the left mouse button is pressed play a sound effect and clear the screen if pythonGraph.mouse_button_released(pythonGraph.mouse_buttons.LEFT): pythonGraph.play_sound_effect('laser.wav') pythonGraph.clear_window(pythonGraph.colors.WHITE) # update window pythonGraph.update_window()
def erase_objects(): pythonGraph.clear_window(pythonGraph.colors.BLACK)