Hardware Reference
In-Depth Information
3. Create a function, findPointOnCircle() . When you pass this function the
centre of the circle and the angle of the clock's hands, the function returns the
position of the clock's hands as shown in FigureĀ 7-5.
def findPointOnCircle(cx, cy, radius, angle):
x = cx + math.sin(math.radians(angle)) * radius
y = cy + math.cos(math.radians(angle)) * radius
x = int(round(x, 0))
y = int(round(y, 0))
return(x,y)
4. Connect to Minecraft and create the MinecraftDrawing object:
mc = minecraft.Minecraft.create()
mcdrawing = minecraftstuff.MinecraftDrawing(mc)
5. Find the player's current position by typing:
pos = mc.player.getTilePos()
6. Now you're going to create variables for the centre of the clock (which will be 25
blocks above the player's position), the radius of the clock face and the length of
the clock hands:
clockMiddle = pos
clockMiddle.y = clockMiddle.y + 25
CLOCK_RADIUS = 20
HOUR_HAND_LENGTH = 10
MIN_HAND_LENGTH = 18
SEC_HAND_LENGTH = 20
7. Next, draw the clock face using drawCircle() by typing:
mcdrawing.drawCircle(clockMiddle.x, clockMiddle.y,
clockMiddle.z,
CLOCK_RADIUS, block.DIAMOND_BLOCK.id)
8. Start an endless loop. All the code after this point will be inside this loop.
while True:
9. Next you need to ask your computer what the time is by using the function
datetime.datetime.now() . You will then split the time into hours, minutes
and seconds. Because your clock is a 12-hour clock, not a 24-hour one, you need
to specify that if the time is after noon, 12 should be subtracted from the hour
(so that, for example, if the time is 14:00, it is shown as 2 o'clock). Do this by
typing the following code:
 
Search WWH ::




Custom Search