Question
PYTHON: I have parts 1 and 2 firgured out: PLEASE help with parts 3, 4 and 5 My code for parts 1 and 2 are:
PYTHON: I have parts 1 and 2 firgured out: PLEASE help with parts 3, 4 and 5
My code for parts 1 and 2 are:
# import graphics, math, random from graphics import * from math import * from random import * # Define function makeControl() def makeControl(): # Create a 300 x 250 Graphics window with a light-grey background # titled Control Panel win = GraphWin('Control Panel',300,250) # Using Rectangles, Text objects and any other Graphics elements # necessary, create the elements in the Control Panel Graphics window
# The GENERATIONS title text is bold and white on a black banner rect1=Rectangle(Point(0,24),Point(300,46)) rect1.draw(win) color2=["black"] rect1.setFill(color2) message1=Text(Point(150,35),"GENERATIONS") color3=["white"] message1.setTextColor(color3) message1.setStyle("bold") message1.draw(win) # The controls are 100x30 Rectangles # START (green), PAUSE (orange), RESET (light blue), QUIT (red) rect2=Rectangle(Point(25,60),Point(125,90)) rect2.draw(win) color4=["lime"] rect2.setFill(color4) message2=Text(Point(75,75),"START") message2.setTextColor(color2) message2.draw(win) rect3=Rectangle(Point(175,60),Point(275,90)) rect3.draw(win) color5=["orange"] rect3.setFill(color5) message3=Text(Point(225,75),"PAUSE") message3.setTextColor(color2) message3.draw(win) rect4=Rectangle(Point(25,110),Point(125,140)) rect4.draw(win) color6=[color_rgb(173, 216,230)] rect4.setFill(color6) message4=Text(Point(75,125),"RESET") message4.setTextColor(color2) message4.draw(win) rect5=Rectangle(Point(175,110),Point(275,140)) rect5.draw(win) color7=["red"] rect5.setFill(color7) message5=Text(Point(225,125),"QUIT") message5.setTextColor(color2) message5.draw(win) # The makeControl() function should return all the Graphics elements # necessary to interact with the Graphics window global glist glist=[] glist.append(win) glist.append(rect1) glist.append(message1) glist.append(rect2) glist.append(message2) glist.append(rect3) glist.append(message3) glist.append(rect4) glist.append(message4) glist.append(rect5) glist.append(message5) return glist
# Define function makeGrid() def makeGrid(): # Create a 400 x 400 Graphics window titled Generations Grid global win2 win2= GraphWin('Generations Grid',400,400) # Create a List of 10x10 Rectangles that fill the Generations Grid # Graphics window (40 rows/columns) global rlist rlist=[] for i in range(0,40): rilist=[] for j in range(0,40): rect="" # The outer-most border of Rectangles should have a black fill with # a black outline if i==0 or i==39 or j==0 or j==39: rect=win2.create_rectangle(i*10, j*10, i*10+10, j*10+10, fill ="black", outline="black") # All other Rectangles have a white fill / black outline else: rect=win2.create_rectangle(i*10, j*10, i*10+10, j*10+10, fill ="white", outline="black") # Return the List of 10x10 Rectangles rilist.append(rect) rlist.append(rect) return rlist
Part 1: Create the Control Panel
Write a function named makeControl() that completes the following tasks:
Create a 300 x 250 Graphics window with a light-grey background titled Control Panel
Using Rectangles, Text objects and any other Graphics elements necessary, create the elements in the Control Panel Graphics window
The GENERATIONS title text is bold and white on a black banner
The controls are 100x30 Rectangles
START (green), PAUSE (orange), RESET (light blue), QUIT (red)
The Text objects should be drawn using the size and font as shown
Your Control Panel should match the colors, font sizes and design shown above
The makeControl() function should return all the Graphics elements necessary to interact with the Graphics window
Thoroughly review the Graphics Library documentation b\ http://mcsp.wartburg.edu/zelle/python/graphics/graphics.pdf
Part 2: Create the Generations Grid
Write a function named makeGrid() that completes the following tasks:
Create a 400 x 400 Graphics window titled Generations Grid
Create a List of 10x10 Rectangles that fill the
Generations Grid Graphics window (40 rows/columns)
The outer-most border of Rectangles should have a black fill with a black outline
All other Rectangles have a white fill / black outline
Return the List of 10x10 Rectangles
Part 3: Bring life() to the Grid
Write a function named life() that completes the following tasks:
Each cell in the Generations Grid has an 18% chance of starting the simulation alive.
Use loops to determine the initial alive or dead status of each of the cells in the Grid.
Set the fill color for the alive cells to red and the fill color for the dead cells to white
Part 4: Create the cycle() function
Write a function named cycle() that completes the following tasks:
Use one or more loops at all eight (8) neighbors to each cell in the Generations Grid.
Determine the change to the current cells status using the following rules
Under Population: A living cell with less than two living neighbor cells should die
Neutral: A living cell with two or three living neighbor cells should stay alive
Over Population: A living cell with more than three living neighbors dies
Reproduction: A dead cell with exactly three living neighbors comes to life
Apply the change to each cells status only after fully analyzing the entire grid
Set the fill color for the alive cells to red and the fill color for the dead cells to white
Part 5: Bring the simulation together with the main() function
Write a function named main() that completes the following tasks:
Call makeControl() to create the Control Panel Graphics window.
Call makeGrid() to create the Generations Grid Graphics window.
Remember: you must assign the objects returned by a function to variables
Define a loop that repeats until a mouse click is detected on the red QUIT control in the Control Panel Graphics window.
If the simulation is not actively running, a mouse click on the green START control in the Control Panel Graphics window will start running the simulation
If the simulation is actively running, a mouse click on the orange PAUSE control in the Control Panel Graphics window will pause the simulation
A mouse click on the light-blue RESET control in the Control Panel Graphics window clears the alive/dead status of all cells by calling the life() function.
If the simulation is running when the light-blue RESET control is clicked, it continues running. If it was paused, it remains paused with the new alive/dead configuration.
Update the Text objects indicating quantity of living cells and current generation number
When the loop ends, close both Graphics windows
You must fully comment all of your Python function(s) describing your design approach as well as the variables, decisions and parameters used.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started