[go: up one dir, main page]

Menu

[72b583]: / tests / c / psclock.c  Maximize  Restore  History

Download this file

138 lines (114 with data), 3.1 kB

  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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <time.h>
#include <libps/pslib.h>
void * my_malloc(PSDoc *p, size_t size, const char *caller) {
void *a;
a = (void *) malloc(size);
return(a);
}
void * my_realloc(PSDoc *p, void *mem, size_t size, const char *caller) {
return((void *) realloc(mem, size));
}
void my_free(PSDoc *p, void *mem) {
free(mem);
}
int main() {
float radius = 200;
float margin = 20;
int pagecount = 600;
int delay = 0;
int alpha;
time_t calendar_time;
struct tm *local_tm;
PSDoc *ps;
PS_boot();
ps = PS_new();
if (0 > PS_open_file(ps, "psclock.ps")) {
printf("Cannot open PostScript file\n");
exit(1);
}
PS_set_parameter(ps, "warning", "true");
PS_set_info(ps, "Creator", __FILE__);
PS_set_info(ps, "Author", "Uwe Steinmann");
PS_set_info(ps, "Title", "Analog Clock");
PS_set_info(ps, "Keywords", "Analog Clock, Time");
while(pagecount-- > 0) {
PS_begin_page(ps, 2 * (radius + margin), 2 * (radius + margin));
PS_set_parameter(ps, "transition", "wipe");
PS_set_value(ps, "duration", 0.5);
PS_translate(ps, radius + margin, radius + margin);
/* minute strokes */
PS_save(ps);
PS_setcolor(ps, "stroke", "rgb", 0.0, 0.0, 1.0, 0.0);
PS_setlinewidth(ps, 2.0);
for (alpha = 0; alpha < 360; alpha += 6) {
PS_rotate(ps, 6.0);
PS_moveto(ps, radius, 0.0);
PS_lineto(ps, radius-margin/3, 0.0);
PS_stroke(ps);
}
PS_restore(ps);
/* 5 minute strokes */
PS_save(ps);
PS_setlinewidth(ps, 3.0);
for (alpha = 0; alpha < 360; alpha += 30) {
PS_rotate(ps, 30.0);
PS_moveto(ps, radius, 0.0);
PS_lineto(ps, radius-margin, 0.0);
PS_stroke(ps);
}
PS_restore(ps);
calendar_time = time(NULL);
local_tm = localtime(&calendar_time);
/* draw hour hand */
PS_save(ps);
PS_rotate(ps,-((local_tm->tm_min/60.0)+local_tm->tm_hour-3.0)*30.0);
PS_moveto(ps, -radius/10, -radius/20);
PS_lineto(ps, radius/2, 0.0);
PS_lineto(ps, -radius/10, radius/20);
PS_closepath(ps);
PS_fill(ps);
PS_restore(ps);
/* draw minute hand */
PS_save(ps);
PS_rotate(ps,-((local_tm->tm_sec/60.0)+local_tm->tm_min-15.0)*6.0);
PS_moveto(ps, -radius/10, -radius/20);
PS_lineto(ps, radius * 0.8, 0.0);
PS_lineto(ps, -radius/10, radius/20);
PS_closepath(ps);
PS_fill(ps);
PS_restore(ps);
/* draw second hand */
PS_save(ps);
PS_setcolor(ps, "stroke", "rgb", 1.0, 0.0, 0.0, 0.0);
PS_setlinewidth(ps, 2);
PS_rotate(ps, -((local_tm->tm_sec - 15.0) * 6.0));
PS_moveto(ps, -radius/5, 0.0);
PS_lineto(ps, radius, 0.0);
PS_stroke(ps);
PS_restore(ps);
/* draw little circle at center */
PS_circle(ps, 0, 0, radius/30);
PS_fill(ps);
PS_end_page(ps);
/* to see some difference */
#ifndef WIN32
if(delay)
sleep(delay);
#endif
}
/*buf = PS_get_buffer(ps);
len = strlen(buf);
printf("Content-type: application/ps");
printf("Content-Length: len");
printf("Content-Disposition: inline; filename=foo.pdf");
printf("\n\n");
printf(buf);
*/
PS_close(ps);
PS_delete(ps);
PS_shutdown();
exit(0);
}