Hardware Reference
In-Depth Information
The math.sin() and math.cos() functions need radians to be passed to
them. Radians are a different way of measuring angles (rather than the often
used 0 - 360 degrees), so the math.radians() function is used to convert
the angles into radians.
3. The x, y values calculated are decimals, but the function needs
whole numbers, so the round() and int() functions are used to
round the decimal number to its nearest whole number and convert
it from decimal to integer:
x = int(round(x, 0))
y = int(round(y, 0))
4. The x and y values are then returned to the program:
return(x,y)
The function returns both the x and y values at the same time, so
the calling program must provide two variables when calling the
function.
You create the hands of the clock using a three-step process:
1. Work out the angle of the hand by dividing 360° by 12 or 60 (depend-
ing whether it is an hour, minute or second hand) and then multiply-
ing that by the number of hours, minutes or seconds:
hourHandAngle = (360 / 12) * hours
2. Find the coordinates (x, y) of the end of the hand using the find-
PointOnCircle() function:
hourHandX, hourHandY = findPointOnCircle(
clockMiddle.x, clockMiddle.y,
HOUR_HAND_LENGTH, hourHandAngle)
As the function returns two values, when it's called two variables
( hourHandX , hourHandY ) are provided.
3. Draw a line from the middle of the clock to the end of the hand:
mcdrawing.drawLine(
clockMiddle.x, clockMiddle.y, clockMiddle.z,
hourHandX, hourHandY, clockMiddle.z,
block.DIRT.id)
 
Search WWH ::




Custom Search