沿周长找到点的坐标



我正在尝试制作一个时钟,我正在尝试根据当前的时间绘制第二,分钟和小时的手,从

中获取它
datetime.datetime.now()

有:

半径,

圆周长度,

和周长的长度(使用以下内容解决:(

circumference = math.pi * (2 * radius)
secs = 10           # for example
secs /= 60          # gets fraction of clock face taken up i.e. for hours I would use /24
secs *= circumference

还是我必须根据时钟的每个季度使用角度来解决它?

谢谢

点坐标更好地从一个角度计算;然后,您需要添加圆心中心位置的画布坐标。

x = radius * math.cos(angle) + center_x
y = radius * math.sin(angle) + center_y

这里显示了一个圆圈上移动点的示例:http://py3.codeskulptor.org/#user301_zopm59qeb1_1.py

import simplegui
import math

radius = 50
offset = 0
def draw(canvas):
    global offset
    canvas.draw_circle([100,100], radius, 2, "Red")
    offset = (offset + 1) % 12
    for t in range(offset, 360+offset, 12):
        angle = t * math.pi / 180
        canvas.draw_circle([radius * math.cos(angle) + 100, radius * math.sin(angle) + 100], 2, 2, 'yellow')
frame = simplegui.create_frame("Home", 200, 200)
frame.set_draw_handler(draw)
frame.start()

最新更新