Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Task 3: Implementing the Update Rule Once the world has been generated and you have added a pattern or two using the blitter, you are

image text in transcribed

Task 3: Implementing the Update Rule Once the world has been generated and you have added a pattern or two using the blitter, you are ready to start the simulation this is done by calling run.simulation) run simulation (opts, vorld) This function creates a figure using matplotlib and plots each pixel in the world grid using the imshow function. Subsequently, FuncAnimation) is called fig ing ani pit. figure() plt, imshow(world, interpolation,none, cmaP",Greys, vmax-1, vmin-o) = animation FuncAnimation(fig, undate-frama fargs-(opts, world, ing), interval-opts.framedelay) pltO The fourth argument supplied to FuncAnimation () specifies how frequently the plot should be automatically updated (in milliseconds. As you can see, this is set on the command line using the framedelay option (See Section 3 and get.commandline.options) in gameoflife.py). The second argument supplied to FuncAnimation) specifies the function that is called for each frame update. The third argument allows you to pass function parameters to the update function in the form of a tuple. In this case we are passing the opts, world, and img parameters to the update.frame ) function. This means that all you need to do to implement the update rule is implement the function update.frame() i def update frame (frame num, opts, orld, img): Accepts: frame num(automatically passed in) current frame number a populated command line options instance world -the 2D world p12el buffer img the plot image img. set array (world) new world 0 for row in world newworld. append (rou:) I YOUR CODE GOES HERE # Copy the contents of the new-world gnto the uorld # (i.e. make the future the present) worldl:] nw world: return img, Here, world contains the current world state, and nev.world will be used to hold the solution to applying If you look at the definition of the update function update.frame), you will notice that it accepts 4 parameters instead of 3. This is because the frame number is automatically passed in as the first argument when the update function is called. Any arguments passed in as a tuple through the third argument of FuncAnination) are passed in after the frame number argument

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data And Databases

Authors: Jeff Mapua

1st Edition

1978502257, 978-1978502253

More Books

Students also viewed these Databases questions