这个模拟时钟中的这部分代码究竟是做什么来移动时钟指针的?
What exactly is this part of code in this analog clock doing to move clock hands?
我不确定这类问题是否能在这里得到解答,但无论如何它都会出现。
# moving hour hand
def moveHourHand():
currentHourInternal = datetime.datetime.now().hour
degree = (currentHourInternal - 15) * -30
currentMinuteInternal = datetime.datetime.now().minute
degree = degree + -0.5 * currentMinuteInternal
hourHand.setheading(degree)
wn.ontimer(moveHourHand, 60000)
# moving minute hand
def moveMinuteHand():
currentMinuteInternal = datetime.datetime.now().minute
degree = (currentMinuteInternal - 15) * -6
currentSecondInternal = datetime.datetime.now().second
degree = degree + (-currentSecondInternal * 0.1)
minuteHand.setheading(degree)
wn.ontimer(moveMinuteHand, 1000)
# moving second hand
def moveSecondHand():
currentSecondInternal = datetime.datetime.now().second
degree = (currentSecondInternal - 15) * -6
secondHand.setheading(degree)
wn.ontimer(moveSecondHand, 1000)
这是 turtle 在 python 中构建的模拟时钟的一部分。 (不是我的。This is the source)这部分是为手的运动创建函数。
我正在制作自己的时钟,并且正在寻找让指针走动的不同方法。这个似乎效果最好,但我真的不明白到底发生了什么。我知道它从 datetime 库中获取了一个值,但之后的一切都令人困惑。特别是 'degree' 的部分。 “15”来自哪里。
所以如果有人能以我能理解的方式解释它,我将不胜感激。
# moving hour hand
def moveHourHand():
currentHourInternal = datetime.datetime.now().hour #Gets current local hour
degree = (currentHourInternal - 15) * -30 #Hour degree, look below
currentMinuteInternal = datetime.datetime.now().minute #Gets minutes for moving the hour hand between hours
degree = degree + -0.5 * currentMinuteInternal #Minute degree, also, look below
hourHand.setheading(degree) #This might send the degree to the function that move the hand
wn.ontimer(moveHourHand, 60000) #Im not sure about this one but i think that tells that function what and when to be called again, in milli seconds (60000ms = 60s = 1m)
小时学位:
-在一个圆圈中,通常,0 度是最右边的点,但在时钟中,0 度是顶点,如图所示。为了补偿 15 个被移动。每个小时之间有 30 度(一圈 360 度/12 小时)。它是负数,因为增加正度数会逆时针。
e.g. (hour - 15) * -30
12 hours -> (12 - 15) * -30 = 90 degrees. Look the images, 90 degrees corresponds to 12h
3 hours -> (3 - 15) * -30 = 360 degrees
6 hours -> (6 - 15) * -30 = 270 degrees
9 hours -> (9 - 15) * -30 = 180 degrees
分度数:
与小时的工作方式类似,乘以 -0.5,因为每小时有 30 度和 60 分钟,计算一下,(30 度/60 分钟)每分钟 1/2 度。和以前一样负数是因为正度数是逆时针的,所以负数是顺时针的。然后将其添加到在数字之间移动时针的总度数。
e.g. (minutes * -0.5)
0 minutes: 0 degrees
15 minutes: -7.5 degrees
30 minutes: -15 degrees
45 minutes: -22.5 degrees
我不确定这类问题是否能在这里得到解答,但无论如何它都会出现。
# moving hour hand
def moveHourHand():
currentHourInternal = datetime.datetime.now().hour
degree = (currentHourInternal - 15) * -30
currentMinuteInternal = datetime.datetime.now().minute
degree = degree + -0.5 * currentMinuteInternal
hourHand.setheading(degree)
wn.ontimer(moveHourHand, 60000)
# moving minute hand
def moveMinuteHand():
currentMinuteInternal = datetime.datetime.now().minute
degree = (currentMinuteInternal - 15) * -6
currentSecondInternal = datetime.datetime.now().second
degree = degree + (-currentSecondInternal * 0.1)
minuteHand.setheading(degree)
wn.ontimer(moveMinuteHand, 1000)
# moving second hand
def moveSecondHand():
currentSecondInternal = datetime.datetime.now().second
degree = (currentSecondInternal - 15) * -6
secondHand.setheading(degree)
wn.ontimer(moveSecondHand, 1000)
这是 turtle 在 python 中构建的模拟时钟的一部分。 (不是我的。This is the source)这部分是为手的运动创建函数。
我正在制作自己的时钟,并且正在寻找让指针走动的不同方法。这个似乎效果最好,但我真的不明白到底发生了什么。我知道它从 datetime 库中获取了一个值,但之后的一切都令人困惑。特别是 'degree' 的部分。 “15”来自哪里。
所以如果有人能以我能理解的方式解释它,我将不胜感激。
# moving hour hand
def moveHourHand():
currentHourInternal = datetime.datetime.now().hour #Gets current local hour
degree = (currentHourInternal - 15) * -30 #Hour degree, look below
currentMinuteInternal = datetime.datetime.now().minute #Gets minutes for moving the hour hand between hours
degree = degree + -0.5 * currentMinuteInternal #Minute degree, also, look below
hourHand.setheading(degree) #This might send the degree to the function that move the hand
wn.ontimer(moveHourHand, 60000) #Im not sure about this one but i think that tells that function what and when to be called again, in milli seconds (60000ms = 60s = 1m)
小时学位:
-在一个圆圈中,通常,0 度是最右边的点,但在时钟中,0 度是顶点,如图所示。为了补偿 15 个被移动。每个小时之间有 30 度(一圈 360 度/12 小时)。它是负数,因为增加正度数会逆时针。
e.g. (hour - 15) * -30
12 hours -> (12 - 15) * -30 = 90 degrees. Look the images, 90 degrees corresponds to 12h
3 hours -> (3 - 15) * -30 = 360 degrees
6 hours -> (6 - 15) * -30 = 270 degrees
9 hours -> (9 - 15) * -30 = 180 degrees
分度数:
与小时的工作方式类似,乘以 -0.5,因为每小时有 30 度和 60 分钟,计算一下,(30 度/60 分钟)每分钟 1/2 度。和以前一样负数是因为正度数是逆时针的,所以负数是顺时针的。然后将其添加到在数字之间移动时针的总度数。
e.g. (minutes * -0.5)
0 minutes: 0 degrees
15 minutes: -7.5 degrees
30 minutes: -15 degrees
45 minutes: -22.5 degrees