Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

def main(): opts = get_commandline_options() world = generate_world(opts) report

ID: 3744587 • Letter: D

Question


def main():
opts = get_commandline_options()
world = generate_world(opts)
report_options(opts)

blit(world, patterns.glider, 20, 20)

run_simulation(opts, world)


if __name__ == '__main__':
main()

Task 2: Writing a Blitter A blitter (short for block image transferer) copies a smaller block of pixel data into a larger pixel buffer at a particular x, y coornate. You are going to write a blitting function in order to help you test out the simulation this will allow you place specifie patterns of cells into the simulation, which will make testing the correctness of your update rule implementation (i.e. Task 3) much easier Again refer to the code in the function main). You will see that once the world is created, we attempt to copy in the pattern of a glider into the world at coordinates (20, 20): blit (world, patterns.glider, 20, 20) Notice that patterns is the name space given to our imported file patterns.py. In this file, I have provided some common patterns with known behaviors. If you open this file, you will see that I have divided the different patterns into groups: Stills These are patterns that do not change when the update rule is ran. They are statically stable. Oscillators These are patterns that don't move around within the world (i.e. their coordinates don't change) but they are in some way animated with a set period. Spaceshipts These are patterns that do move around within the world. . Generators These are patterns that are capable of producing other independent patterns. In the gameoflife.py skeleton provided, the function blit doesn't do anything: def blit world, sprite, x, y): Accepts: world a 2D world pizel buffer generated by generate worldO sprite-a 2D matriz containing a pattern of is and Os world coord where left edge of sprite will be placed y world coord where top edge of sprite will be placed Returns: (Nothing) Description: Copies a 2D pizel pattern (.e sprite) into the Larger 2D world. The sprite will be copied into the 2D world with its top left corner being Located at world coordinate (z, y) YOUR CODE GOES HERE It is your job to populate this function. Test your implementation by generating an empty simulation world and placing a glider pattern at coordinates (20, 20)

Explanation / Answer

here is your function : ------------------>>>>>>>>>>>>>

def blit(world,sprite,x,y):
    """
    Accepts: world -- a 2D world pixel buffer generated by generate_world()
             sprite -- a 2D matrix containing a pattern of 1s and os
             x      -- x world coord where left edge of sprite will be placed
    """
    i = 0
    j = 0
    for k in range(x,len(sprite)):
        j = 0
        for l in range(y,len(sprite[k])):
            world[k][l] = sprite[i][j]
            j = j + 1
        i = i + 1

#if not work please comment me the world data structure and patterns datastructure