Question: Program in Python: In this exercise you will build a program creates some modern art a random collection of points. There will be a random

Program in Python: In this exercise you will build a program creates some modern art a random collection of points. There will be a random number of points with random locations and random colors drawn on a square screen. See the Sample Output for what your program might produce. The design of this program is broken into several parts: (1) Create a random number of coordinates saved in a set of tuples; (2) Create a matrix that is loaded with True at each of the coordinates (it will contain False everywhere else); (3) Use this matrix to control where the random points are drawn; (4) The program stops when the user clicks the mouse anywhere on the screen. Specifications: Here are the things you need to do: 1. Write a function called create_matrix(wid) that creates a wid x wid matrix loaded with False values. The function returns the created matrix to its caller. 2. Write a fruitful function called create_set(high) that builds a set containing a random number of coordinate tuples. The x and y values for these coordinates must be in the range 0..high. You will accumulate each random coordinate in a set so that no duplicate coordinates are saved. The number of coordinates should be random, but you need to ensure that the size of the set does not get too large. The maximum number of coordinates should be just a fraction of the maximum size of the set (which is high^2). A fraction of much less than 5% might be a good starting value. The function returns a set of coordinate tuples. 3. Write a function called load_data(data_matix, tuples) that loads the provided matrix with True values using the tuples data as the coordinates where True is to be inserted. 4. Build a function called create_art() that: a. Uses create_matrix() to create a coordinate matrix b. Uses create_set() to create a set of random coordinates c. Uses load_data() to load the coordinate matrix with True values at the locations specified by the coordinate tuples d. Sets up a Turtle environment including a title for the window, a background color of your choice e. Uses the TurtleSupport.py modules draw_dot() or draw4dots() function to place dots at the locations specified by the data matrix. Everywhere that the data matrix contains a True value, you should use the row and column as locations where a dot should be drawn (In the sample output below I used draw4dots()) f. The drawing should take place as fast as possible, preferably instantaneously

g. This function should use the exitonclick() function to terminate execution 5. Build a main driver that calls create_art(). Run your program at least 3 times. Hint: get steps (a) through (c) working perfectly with a small matrix before moving on to the remaining steps. Your final program should use something like a 500 x 500

Here is what I have, but I keep receiving a index error and I really need assistance. Thanks!

import random import turtle import TurtleSupport

if __name__ == "__main__": # Set up window environment when run as main WIDTH = 600 ; HEIGHT = 400 wn = turtle.Screen() wn.bgcolor('#fceac2') wn.setup(WIDTH, HEIGHT)

# Set up the turtle t = turtle.Turtle() t.screen.title('Turtle Support for Art.py... Click to quit') t.hideturtle() t.speed(0)

def create_matrix(wid): return[[False for _ in range(wid)] for _ in range(wid)]

def create_set(high): num_point = int(0.02 * high ** 2) set_point = set() while len(set_point) < num_point: x = random.randint(0, high) y = random.randint(0, high) set_point.add((x, y)) return set_point

def load_data(data_matrix, tuples): for x, y in tuples: data_matrix[x][y] = True def create_art(): data_matrix = create_matrix(WIDTH) tuples = create_set(WIDTH) load_data(data_matrix, tuples) wn.bgcolor('tan') t.title('Cool Art') for x in range(WIDTH): for y in range(WIDTH): if data_matrix[x][y]: TurtleSupport.draw4dots(x - WIDTH/2, y - WIDTH/2, 5, 'blue')

def draw_dot(p, x, y): """ Draw a radius 15 dot at (x,y) """ p.penup() p.goto(x, y) p.pendown() p.dot(15, (random(), random(), random())) def draw4dots(p, x, y): """ Draw 4 dots based at (x,y) """ draw_dot(p, x, y) draw_dot(p, -x, y) draw_dot(p, x, -y) draw_dot(p, -x, -y)

def draw_axes(p, w, h): """ Draw black axes """ p.color('black') p.pensize(0) p.penup() ; p.goto(0, -w) ; p.pendown(); p.goto(0, w) p.penup() ; p.goto(-h, 0) ; p.pendown(); p.goto(h, 0)

if __name__ == "__main__": """ Run a short test if executed as main """ create_art() wn.tracer(0,0) draw_axes(t, WIDTH, HEIGHT) draw4dots(t, 50, 50) draw4dots(t, 75, 125) draw4dots(t, 200, 20) wn.update() wn.exitonclick()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!