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
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
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)](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F518d5b01-a081-4158-af5e-3484c0c31611%2F406589e6-bbc8-44ff-ab91-19944b6ed98e%2Fa4sh27b_processed.png&w=3840&q=75)
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

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 2 images

Knowledge Booster
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.Recommended textbooks for you

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)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

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)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education