Question: 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

 Task 3: Implementing the Update Rule Once the world has been

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!