In this project, we'll build on the sprite animations we did in the LED Matrix project by not only animating a running man on the LED Matrix, but also creating a synchronized animation of the running man in the Minecraft world. What we draw on the LED Matrix will be replicated in blocks in the Minecraft world.

This project will only require the LED Matrix display. Here is what your breadboard should look like:

Our code for this project will be identical to our code in the project, with one addition — we'll create a function that will replicate the animation we're doing on the LED Matrix in the Minecraft world as well.

When you give this code a try, don't forget to look around to find the running man!

Here is what the full code for this project should look like. We'll dig further into the highlighted pieces of code below:

sprite_in_minecraft() Function

We've created a function that will animate our character in the Minecraft world. Unlike the LED Matrix, where we can use a simple API to pass in an 8x8 design (a sprite) with a single function call, to create a design in the Minecraft world, we need to draw it block-by-block. For that reason, the bulk of our function is used to turn our 8x8 list of 0's and non-0's into blocks (for the non-0's) and air (for the 0's).

Let's discuss what our function does, line-by-line:

enumerate() Function

In the two for loops above, we use the built-in enumerate function. This function allows us to track the count of how many times we've gone through the for loop — we call this the "index", it starts at 0 and it is stored in the first variable of the loop.

Here's an example:

animals = ['dog', 'cat', 'bird']
for index, animal in (enumerate(animals)):
    print(index, animal)

This code would output:

0 dog
1 cat
2 bird
  1. We made the running man out of wood. Can you change the type of block that the running man is made of?

  2. Can you make the running man out of stripes? That is, can you use different materials for the odd and even rows?

  3. Can you make the running man out of randomly generated materials for each block?

  4. We made the running man stand straight up in the Minecraft world (on the X and Y axes). Can you lay the running man down flat (on the X and Z axes)?