Animated City

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0

The purpose of the task was to make an animated city scene. The main tasks were to use primitive, aggregate, and scene to create the final scene. With each object there could be animation.

The first task was to draw the cityscape and make a collection of complex objects. The complex objects I used were car, building, sky, and person. I also had a road object but it has no animation. Each of my object files at an init function, draw function and animate function. Then each of these files had a main function to test the object before putting it into the scene.py file. An example of a complex object is my car:

Then I had to create the scene.py file that would call all my images and make the scene. An important part of the scene.py file is the duples used. In the sceneInit function I needed to call the complex object I wanted, create a duple for it and then append it to the scene:
def sceneInit( x, y, scale ):
scenelist = []

#sky object
s = sky.skyInit( x, y, scale )
scenelist.append( ('sky', s) )

another example is the buildings:
#different buildings lining the road
b = building.buildingInit( x+10*scale, y+145*scale, scale*1.1 )
scenelist.append( ('building', b) )
b = building.buildingInit( x+110*scale, y+105*scale, scale*1.3 )
scenelist.append( ('building', b) )

by doing this I was able to create a list of all my objects and add them to the scene by setting their x, y values and the scale.

The next step was to draw each item. I crated a loop to draw the second item in each duple like this:
def sceneDraw( scenelist, win ):
for duple in scenelist:
aggregate.draw( duple1, win )

Next was to animate each complex object. The objects that needed animation had to have a frameNum in the functions:
def sceneAnimate( scenelist, frameNum ):
for duple in scenelist:
if duple0 == 'car':
car.carAnimate( duple1, frameNum )

Finally I created the main function to put the whole scene together. First I created the window by using graphics.GraphWin, then called sceneInit, called sceneDraw, gave a frameNum and then created a while loop to see the animation.

The last test was to make a scene2.py file to scale scene one into different sizes or more than one time. I made my copies all the same size and right in a row so that my cars would drive through the city and make the road seem long.

I learned how to animate objects and make more complex objects. I learned new organization strategies and better ways to make lists to call certain files. It is easier to import files and create one main program than to put everything into one large file.