Circles and Spheres

In our first class we learned about functions. A function is a task to do something. Some of the functions we used are mc.postToChat to post a message to Minecraft and time.sleep to pause our program execution for 1 second. In today's adventure, we learn more about functions. We will use new functions to build circles and spheres in Minecraft.

Functions and arguments

In our previous class we were introduced to functions. Sometimes you need more than just a task name to complete a task.

E.g., "Practice you writing!", is not enough, you want to know for how long. "Practice your writing for 15 minutes!" is more helpful.

If we had a function for the "practice writing" task, we would write is as,

practiceWriting(15)

the additional pieces information we pass to a function are called its arguments. A function can have zero or more arguments just like a real tasks need zero or more pieces of information to complete them. Both the functions that you used so far needed arguments. For the function examples below,

mc.postToChat("Hi Kids")
time.sleep(1)

The mc.postToChat function needs the argument "Hi Kids" which is the message to post to the Minecraft chat window. The time.sleep function needs the argument 1 which is the number of seconds to pause the program from running.

Building functions

The first building function drawings.drawMyCircle uses two arguments - the radius of the circle to build and the block id to use for building the circle.

drawings.drawMyCircle(radius,blockId)
# e.g., drawings.drawMyCircle(5,block.STONE.id)

The second building function drawings.drawMySphere uses two arguments - the radius of the sphere to build and the block id to use for building the sphere.

drawings.drawMySphere(radius,blockId)
# e.g., drawings.drawMySphere(5,block.STONE.id)

In the following tasks, you will use these functions with different arguments to build circles and spheres in Minecraft.

Note: Before you start your tasks, start Minecraft and run the program cell below to make the building functions available to your programs.


In [ ]:
import sys
sys.path.append('/home/pi/minecraft-programming')
import mcpi.block as block
import time
import drawings

Task 1

Use the building functions to build three circles with radii 5, 9 and 13 in the same position (center).


In [ ]:
# Task 1 program

Task 2

Use the building functions to build three spheres of radius 5, 9 and 13 in three different positions.


In [ ]:
# Task 2 program

Task 3

Write a program to build a sphere of radius 5 at the center, a circle of radius 8 and a circle of radius 13 at Steve's current position


In [ ]:
# Task 3 program

Task 4

Use a new function drawings.drawMyHollowSphere. The function takes two arguments. First the radius of the hollow sphere to build and second, the blockId to use for building the hollow sphere.


In [ ]:
# Task 4 program