Six steps to complete in M4Lab2 # Define a list to store 3 colors # Define statements for each mouse button # Within the program suite, draw on screen with a different color # When your program runs, a black box appears.  # Draw with a different color using the left, middle, and right cursor buttons # The middle cursor is the scrollwheel. You can configure a random color. # Close the draw window. In the Python shell, type exit() to quit

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Six steps to complete in M4Lab2
# Define a list to store 3 colors
# Define statements for each mouse button
# Within the program suite, draw on screen with a different color
# When your program runs, a black box appears. 
# Draw with a different color using the left, middle, and right cursor buttons
# The middle cursor is the scrollwheel. You can configure a random color.
# Close the draw window. In the Python shell, type exit() to quit

import pygame
import random # optional for this program, but useful for random colors, such as
# randcolor = random.randrange (0, 255)
pygame.init()
# Defines the display size with a width and height of 300, 300
size = width, height = 300, 300
# Step 1: Define a colors list to describe 3 colors.
# Hint, use their RGB number values
screen = pygame.display.set_mode(size)
# Draws the screen using the size
pygame.display.set_caption("Click and drag to draw")
# Displays the title at the top of the draw screen
keep_going
# The program continues unti you close the window and type exit() in the shell
= True
# Step 2: define a radius variable for your pen at 5, 10 or 15
# Test them to see which radius you prefer and use it.
mousedown = False
# we have not started drawing yet
while keep_going != False:
for event in pygame.event.get():
if event.type == pygame.QUIT:
keep_going
pygame.quit()
if event.type
False
== pygame. MOUSEBUTTONDOWN:
lown True
if event.type == pygame. MOUSEBUTTONUP:
mousedown = False
mou:
if mousedown: # start drawing
spot = pygame.mouse.get_pos() # locate the pen's position as the 1st spot
if pygame. mouse.get_pressed () [0]: # Boolean for button 1
button_color = colors[0] # selects the first color from the list
# Step 3: write the elif for pressing button 2, similar to button 1
# Step 4: write the statement for button 2's color
# Step 5: write the else statement for button 3
# Step 6: choose a color from the list
pygame.draw.circle(screen, button_color, spot, radius)
# The pen is in the shape of a circle that draws on the screen
# using the button color, the position of the spot, and the pen's radius
pygame.display.update()
# You can draw until you close the Pygame window
pygame.quit ( )
# The program ends after you type exit() in the Python shell.
# For fun, try defining a random color and calling it for button_color
# randcolor = random.randrange (0,255)
Transcribed Image Text:import pygame import random # optional for this program, but useful for random colors, such as # randcolor = random.randrange (0, 255) pygame.init() # Defines the display size with a width and height of 300, 300 size = width, height = 300, 300 # Step 1: Define a colors list to describe 3 colors. # Hint, use their RGB number values screen = pygame.display.set_mode(size) # Draws the screen using the size pygame.display.set_caption("Click and drag to draw") # Displays the title at the top of the draw screen keep_going # The program continues unti you close the window and type exit() in the shell = True # Step 2: define a radius variable for your pen at 5, 10 or 15 # Test them to see which radius you prefer and use it. mousedown = False # we have not started drawing yet while keep_going != False: for event in pygame.event.get(): if event.type == pygame.QUIT: keep_going pygame.quit() if event.type False == pygame. MOUSEBUTTONDOWN: lown True if event.type == pygame. MOUSEBUTTONUP: mousedown = False mou: if mousedown: # start drawing spot = pygame.mouse.get_pos() # locate the pen's position as the 1st spot if pygame. mouse.get_pressed () [0]: # Boolean for button 1 button_color = colors[0] # selects the first color from the list # Step 3: write the elif for pressing button 2, similar to button 1 # Step 4: write the statement for button 2's color # Step 5: write the else statement for button 3 # Step 6: choose a color from the list pygame.draw.circle(screen, button_color, spot, radius) # The pen is in the shape of a circle that draws on the screen # using the button color, the position of the spot, and the pen's radius pygame.display.update() # You can draw until you close the Pygame window pygame.quit ( ) # The program ends after you type exit() in the Python shell. # For fun, try defining a random color and calling it for button_color # randcolor = random.randrange (0,255)
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps with 2 images

Blurred answer
Knowledge Booster
List
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education