我不确定这类问题是否在这里得到了回答,但不管怎样,还是在这里
# 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库中获取了一个值,但之后的一切都令人困惑。尤其是带有“度”的部分。“15”来自哪里
如果有人能以我能理解的方式解释,我将不胜感激
小时学位:
-在圆中,通常0度是最右点,但在时钟中,0度是顶点,如图所示。以证明15人被起诉。每小时之间有30度(360度圆/12小时)。它是负的,因为增加正的度数是逆时针的
分钟学位:
工作原理与小时类似,乘以-0.5,因为每小时有30度和60分钟,计算一下,(30度/60分钟)每分钟1/2度。和以前一样,这是因为正度数与时钟方向相反,所以负度数与时钟方向相反。然后将其添加到总度数中,以便在数字之间移动时针
相关问题 更多 >
编程相关推荐