For this week's project we used Zelle graphics to create another cityscape, this time with animated components. We incorporated several of the tools we've used over the course of the semester to write our code more efficiently (, adding comments frequently to make it more clear and readable. I created two building functions that took in four parameters (win, x0, y0, dx), and then two functions with for loops that animated the buildings. I then created one more function that took in parameters for each building (win, x0, y0, dx, x1, y1, bx) so that both loops would animate the buildings at once, rather than sequentially.
I couldn't get the animation to work on the webpage, but here are some screen shots of the buildings at different times:
In order to make my code more efficient, I used parameters with scale factors that would apply to all of my functions so I don't have to change each one. I also made good use of loops in order to create my windows and animation. For example, I used a for loop in which the y-value of each window increased each time through the loop, thus positioning and spacing the windows without having to write code for each one. Here's a snippet:
For my animation, I put elements of my building into a list and then created a function with a for loop that goes through that list and changes the color based on a random number generator. I then made a fifth function that executes the flash function (and the lights function) 50 times. For example:
For extensions, I made the text in my second building flash using colors decided by random. As I mentioned before, in order to get my text and windows flash at the same time, I had to create a fifth function. I tried to use a while True function as you suggested, but I couldn't get it work, so I just decided to make a new function altogether. I also used the polygon to make the windows of this building look like lightning bolts(kind of, at least) to give it more of an arcade feel.