5 # From tclock.c, Copyright Howard Jones <ha.jones@ic.ac.uk>, September 1994.
16 def A2XY(angle
, radius
):
17 return (int(round(ASPECT
* radius
* sin(angle
))),
18 int(round(radius
* cos(angle
))))
21 stdscr
.addch(y
, x
, col
)
23 # draw a diagonal line using Bresenham's algorithm
24 def dline(pair
, from_x
, from_y
, x2
, y2
, ch
):
25 if curses
.has_colors():
26 stdscr
.attrset(curses
.color_pair(pair
))
72 my_bg
= curses
.COLOR_BLACK
77 if curses
.has_colors():
78 curses
.init_pair(1, curses
.COLOR_RED
, my_bg
)
79 curses
.init_pair(2, curses
.COLOR_MAGENTA
, my_bg
)
80 curses
.init_pair(3, curses
.COLOR_GREEN
, my_bg
)
82 cx
= (curses
.COLS
- 1) // 2
83 cy
= curses
.LINES
// 2
84 ch
= min( cy
-1, int(cx
// ASPECT
) - 1)
85 mradius
= (3 * ch
) // 4
89 for i
in range(0, 12):
90 sangle
= (i
+ 1) * 2.0 * pi
/ 12.0
91 sdx
, sdy
= A2XY(sangle
, sradius
)
93 stdscr
.addstr(cy
- sdy
, cx
+ sdx
, "%d" % (i
+ 1))
96 "ASCII Clock by Howard Jones <ha.jones@ic.ac.uk>, 1994")
98 sradius
= max(sradius
-4, 8)
104 t
= time
.localtime(tim
)
106 hours
= t
[3] + t
[4] / 60.0
110 mangle
= t
[4] * 2 * pi
/ 60.0
111 mdx
, mdy
= A2XY(mangle
, mradius
)
113 hangle
= hours
* 2 * pi
/ 12.0
114 hdx
, hdy
= A2XY(hangle
, hradius
)
116 sangle
= t
[5] * 2 * pi
/ 60.0
117 sdx
, sdy
= A2XY(sangle
, sradius
)
119 dline(3, cx
, cy
, cx
+ mdx
, cy
- mdy
, ord('#'))
121 stdscr
.attrset(curses
.A_REVERSE
)
122 dline(2, cx
, cy
, cx
+ hdx
, cy
- hdy
, ord('.'))
123 stdscr
.attroff(curses
.A_REVERSE
)
125 if curses
.has_colors():
126 stdscr
.attrset(curses
.color_pair(1))
128 plot(cx
+ sdx
, cy
- sdy
, ord('O'))
130 if curses
.has_colors():
131 stdscr
.attrset(curses
.color_pair(0))
133 stdscr
.addstr(curses
.LINES
- 2, 0, time
.ctime(tim
))
135 if (t
[5] % 5) == 0 and t
[5] != lastbeep
:
143 plot(cx
+ sdx
, cy
- sdy
, ord(' '))
144 dline(0, cx
, cy
, cx
+ hdx
, cy
- hdy
, ord(' '))
145 dline(0, cx
, cy
, cx
+ mdx
, cy
- mdy
, ord(' '))