78.7k views
2 votes
You should see the following code in your programming environment:

import simplegui

def draw_handler(canvas):
# your code goes here

frame = simplegui.create_frame('Testing', 600, 600)
frame.set_canvas_background("Black")
frame.set_draw_handler(draw_handler)
frame.start()
Use the code above to write a program that, when run, draws 1000 points at random locations on a frame as it runs. For an added challenge, have the 1000 points be randomly red, green, or blue.

Hint: The colors can be represented by

Red: “RGB(255, 0, 0)”

Green: “RGB(0, 255, 0)”

Blue: “RGB(0, 0, 255)”

User Daum
by
8.2k points

1 Answer

4 votes

Final answer:

To draw 1000 points at random locations with random colors, use the Python programming language and the simplegui library.

Step-by-step explanation:

To draw 1000 points at random locations with random colors, use the Python programming language and the simplegui library. Here's the modified code:

  1. Import the necessary libraries: import simplegui
  2. Create a drawing handler function that takes a canvas as a parameter: def draw_handler(canvas)
  3. Inside the drawing handler function, use a loop to generate 1000 random points on the canvas. For each point, randomly select a color (red, green, or blue) and draw a colored circle at the random location.
  4. Create a frame using simplegui.create_frame() and set its properties.
  5. Set the canvas background color using frame.set_canvas_background().
  6. Set the drawing handler function for the frame using frame.set_draw_handler().
  7. Start the frame using frame.start().

User Rudy S
by
8.2k points