1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
#include "library.h"
const double pi = acos(-1.0);
int get_times(/*int year, int month, int day,*/ int hour, int minute, int second)
{
//year = get_calendar_date() / 10000;
//month = (get_calendar_date() / 100)%100;
//day = (get_calendar_date() % 10000)%100;
hour = get_clock_time() / 10000;
minute = (get_clock_time() / 100)%100;
second = (get_clock_time() % 1000)%100;
//print("Year: "); print(year);
//new_line();
//print("Month: "); print(month);
//new_line();
//print("Day: "); print(day);
new_line();
if(hour > 12)
{
print("Hour: "); print(hour-12); print(" P.M.");
}
else
{
print("Hour: "); print(hour); print(" A.M.");
}
new_line();
print("Minute: "); print(minute);
new_line();
print("Second: "); print(second);
return(second);
}
void circle(int const R, int counter)
{
set_pen_width(3);
if(counter<=360)
{
counter = counter+1;
draw_distance((2*pi*R)/360);
turn_right_by_degrees(1);
circle(R,counter);
}
}
void ticks(int num)
{
if(num<12)
{
set_heading_degrees(30*num);
set_pen_width(2);
set_pen_color(color::white);
move_to(200,200);
draw_distance(150);
set_pen_color(color::black);
draw_distance(25);
ticks(num+1);
}
}
void hour_hand(int hour, int minute)
{
set_heading_degrees(hour*30 + minute*0.5);
move_to(200,200);
set_pen_color(color::black);
set_pen_width(3);
draw_distance(80);
}
void minute_hand(int minute)
{
set_heading_degrees(minute*6);
move_to(200,200);
set_pen_color(color::black);
set_pen_width(3);
draw_distance(120);
}
void second_hand(int second)
{
set_heading_degrees(second*6);
move_to(200,200);
set_pen_color(color::red);
set_pen_width(2);
draw_distance(120);
}
void run_clock(int hour, int minute, int second)
{
while(true)
{
get_times(hour,minute,second);
second_hand(second);
minute_hand(minute);
hour_hand(hour, minute);
wait(0.02);
}
}
void main()
{
int year = 0;
int month = 0;
int day = 0;
int hour = 0;
int minute = 0;
int second = 0;
int counter = 0;
int R = 175;
int num = 0;
make_window(400,525);
move_to(25,200);
circle(R,counter);
ticks(num);
//hour_hand(hour, minute);
//minute_hand(minute);
//second_hand(second);
run_clock(hour,minute,second);
}
|