I have been given an assignment to create a random race program where 2 different lines race. How the lines travel is determined by a random number generator, but that is not the issue I currently have. I am suppose to create a window that is 500x600, with the x- and y-axises being 2 pixels wide. I am suppose to also include lines along the x- and y-axises at -40, -20, 20, and 40.
I am using graphics.py. My professor will dock points if I use anything else.
One of the problems I am encountering is that python will freeze whenever I try to run the program to see if anything was placed in the window correctly. I do not know if this has anything to with my code, graphics.py, or python itself.
The other issue I am asking for help with is getting the graph created. During the odd occasion where python does not freeze, I am only capable of producing the yellow information box and the x- and y-axises. If I try to add any other code to it, the window fails to display anything, and I am not sure why. I know that I need to implement a loop to efficiently create all the other lines.
The following is my code thus far:
from graphics import* import math def buildWindow(win): yAxis = Line(Point(0, -50), Point(0, 50)) yAxis.setFill("black") yAxis.draw(win) xAxis = Line(Point(-50, 0), Point(50, 0)) xAxis.setFill("black") xAxis.draw(win) information = Rectangle(Point(-50, -50), Point (50, -40)) information.setFill("yellow") information.draw(win) #def generateData(): def main(): win = GraphWin("Random Race",500,600) win.setCoords(-50,-50,50,50) buildWindow(win) main()
The information box is meant to display the current distance from the origin of each "racer", as well as the maximum distance each racer achieved. However, that is not important at the moment. Getting python to stop freezing and crashing, as well as plotting the graph is what is important. If anyone can, please help me out. Your assistance will be well appreciated.