def draw_on(): """ TODO #1: Complete and test the draw_on function. Functionality is described in the comments below. Test prior to continuing. """ if pythonGraph.mouse_button_down(pythonGraph.mouse_buttons.LEFT): if place_image == True: pythonGraph.draw_image('lander.jpg', mouse_x, mouse_y, 29, 29) else: pythonGraph.draw_circle(mouse_x, mouse_y, 10, color, True)
def draw_on(): # if the mouse is not on the pallet and the left mouse button is down do the following # if an image is to be drawn draw an image at the current mouse location # otherwise draw a circle at the current mouse location # if the mouse is not on the pallet and the left mouse button is down draw the image or the circle based # on global variables place_image if (mouse_y >= 30 or mouse_x >= 150) and pythonGraph.mouse_button_down( pythonGraph.mouse_buttons.LEFT): if not place_image: pythonGraph.draw_circle(mouse_x, mouse_y, radius, color, True) else: pythonGraph.draw_image('lander.jpg', mouse_x, mouse_y, 29, 29) if laser_on: pythonGraph.play_sound_effect('laser.wav')
""" 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 draw_ball(): pythonGraph.draw_circle(ball_1_x, ball_1_y, BALL_RADIUS, pythonGraph.colors.BLUE, True) pythonGraph.draw_circle(ball_2_x, ball_2_y, BALL_RADIUS, pythonGraph.colors.RED, True)
animate = False # Setup tasks for window pythonGraph.open_window(SCREEN_WIDTH, SCREEN_HEIGHT) pythonGraph.set_window_title(SCREEN_TITLE) # Animation Loop while pythonGraph.window_not_closed(): pythonGraph.clear_window(pythonGraph.colors.WHITE) # Draws Some Text pythonGraph.draw_text("# of Times Drawn: " + str(frame_count), 0, 0, pythonGraph.colors.BLACK) # Draws the Circle pythonGraph.draw_circle(ball_x, ball_y, 35, pythonGraph.colors.RED, True) # Toggles Animation Mode if pythonGraph.key_pressed('space'): animate = not animate if animate or pythonGraph.mouse_button_pressed( pythonGraph.mouse_buttons.LEFT): ball_x = ball_x + ball_x_velocity ball_y = ball_y + ball_y_velocity if ball_x < 0 or ball_x > SCREEN_WIDTH: ball_x_velocity *= -1 if ball_y < 0 or ball_y > SCREEN_HEIGHT: ball_y_velocity *= -1
ball_y = [] ball_x_velocity = [] ball_y_velocity = [] ball_radius = [] ball_color = [] # Setup tasks for window pythonGraph.open_window(SCREEN_WIDTH, SCREEN_HEIGHT) pythonGraph.set_window_title(SCREEN_TITLE) # Animation Loop while pythonGraph.window_not_closed(): pythonGraph.clear_window(pythonGraph.colors.WHITE) for i in range(0, len(ball_x)): pythonGraph.draw_circle(ball_x[i], ball_y[i], ball_radius[i], ball_color[i], True) ball_x[i] += ball_x_velocity[i] ball_y[i] += ball_y_velocity[i] if ball_x[i] < 0 or ball_x[i] > SCREEN_WIDTH: ball_x_velocity[i] *= -1 if ball_y[i] < 0 or ball_y[i] > SCREEN_HEIGHT: ball_y_velocity[i] *= -1 if pythonGraph.mouse_button_pressed(pythonGraph.mouse_buttons.LEFT): ball_x.append(pythonGraph.get_mouse_x()) ball_y.append(pythonGraph.get_mouse_y()) ball_x_velocity.append(random.randint(1, 10)) ball_y_velocity.append(random.randint(1, 10)) ball_radius.append(random.randint(10, 30))
import pythonGraph pythonGraph.open_window(600, 600) while pythonGraph.window_not_closed(): if (pythonGraph.mouse_button_down(pythonGraph.mouse_buttons.LEFT)): mouse_x = pythonGraph.get_mouse_x() mouse_y = pythonGraph.get_mouse_y() pythonGraph.draw_circle(mouse_x, mouse_y, 10, pythonGraph.colors.BLUE, True) pythonGraph.update_window()
DELTA = 10 color = pythonGraph.colors.BLUE while pythonGraph.window_not_closed(): # erase pythonGraph.clear_window(pythonGraph.colors.WHITE) # if arrow keys are pressed and held down move the circle if pythonGraph.key_down('up'): y -= DELTA if pythonGraph.key_down('down'): y += DELTA if pythonGraph.key_down('left'): x -= DELTA if pythonGraph.key_down('right'): x += DELTA # draw a circle at the given corrodinates pythonGraph.draw_circle(x, y, 20, color, True) # if the 'q' key is pressed quit the program if pythonGraph.key_pressed('q'): pythonGraph.close_window() # if the 'c' key is pressed change the color of the circle to a random color if pythonGraph.key_pressed('c'): color = pythonGraph.create_random_color() # update window pythonGraph.update_window()
def draw_ball(): pythonGraph.draw_circle(ball_x, ball_y, 10, color, True)
import pythonGraph SCREEN_TITLE = "Python Graph Demonstration" SCREEN_WIDTH = 600 SCREEN_HEIGHT = 600 # Setup tasks for window pythonGraph.open_window(SCREEN_WIDTH, SCREEN_HEIGHT) pythonGraph.set_window_title(SCREEN_TITLE) # DRAWING goes here pythonGraph.draw_circle(290, 250, 100, pythonGraph.colors.YELLOW, True) pythonGraph.draw_circle(250, 200, 20, pythonGraph.colors.BLACK, True) pythonGraph.draw_circle(330, 200, 20, pythonGraph.colors.BLACK, True) pythonGraph.draw_line(230, 300, 350, 300, pythonGraph.colors.BLACK) # Wait using the window is closed pythonGraph.wait_for_close()