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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
|
/* -*- Mode: C; tab-width: 4 -*- */
/* toneclock --- Screenhack inspired by Peter Schat's toneclock
*/
#if !defined( lint ) && !defined( SABER )
static const char sccsid[] = "@(#)toneclock.c 5.00 2004/09/16 xlockmore";
#endif
/*-
* Copyright (c) 2004 by Jouk Jansen <joukj@hrem.stm.tudelft.nl>
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose and without fee is hereby granted,
* provided that the above copyright notice appear in all copies and that
* both that copyright notice and this permission notice appear in
* supporting documentation.
*
* This file is provided AS IS with no warranties of any kind. The author
* shall have no liability with respect to the infringement of copyrights,
* trade secrets or any patents by this file or any part thereof. In no
* event will the author be liable for any lost revenue or profits or
* other special, indirect and consequential damages.
*
* The author should like to be notified if changes have been made to the
* routine. Response will only be guaranteed when a VMS version of the
* program is available.
*
* Toneclock. Peter Schat (1937-2003) was a Dutch composer. Het invented
* the toneclock, a garphical representation of the tonesystem.
*
* Revision History:
* 20-Dec-2004: Initial release
* 23-Dec-2004: -size determines size of the clock
* -original ignores all options and displays original clock
* -pulsate make the clock pulsating
* 24-Dec-2004: -fill num
* polygon filling chance implemented
* 04-Jan-2005: -move allow moving for small clocks
* 16-Feb-2005: -Number of hours according to "count" option
* -Random polygons
*
*/
#if 0
#define NO_DBUF
#endif
#ifdef STANDALONE
#define MODE_toneclock
#define PROGCLASS "toneclock"
#define HACK_INIT init_toneclock
#define HACK_DRAW draw_toneclock
#define toneclock_opts xlockmore_opts
#define DEFAULTS "*delay: 60000 \n" \
"*count: -20 \n" \
"*cycles: 200 \n" \
"*size: -1000 \n" \
"*ncolors: 64 \n" \
"*fullrandom: True \n" \
"*verbose: False \n"
#include "xlockmore.h" /* in xscreensaver distribution */
#else /* STANDALONE */
#include "xlock.h" /* in xlockmore distribution */
#include "color.h"
#endif /* STANDALONE */
#ifdef MODE_toneclock
#define DEF_NUM_hour 12
#define DEF_CYCLE "True"
#define DEF_ORIGINAL "False"
#define DEF_PULSATING "False"
#define DEF_MOVE "True"
#define DEF_FILL "0"
static Bool cycle_p , original , pulsating , move_clock;
static int fill;
static XrmOptionDescRec opts[] =
{
{(char *) "-fill", (char *) "tomecloc.fill", XrmoptionSepArg, (caddr_t) NULL},
{(char *) "-cycle", (char *) ".toneclock.cycle", XrmoptionNoArg, (caddr_t) "on"},
{(char *) "+cycle", (char *) ".toneclock.cycle", XrmoptionNoArg, (caddr_t) "off"},
{(char *) "-original", (char *) ".toneclock.original", XrmoptionNoArg, (caddr_t) "on"},
{(char *) "+original", (char *) ".toneclock.original", XrmoptionNoArg, (caddr_t) "off"},
{(char *) "-move", (char *) ".toneclock.move", XrmoptionNoArg, (caddr_t) "on"},
{(char *) "+move", (char *) ".toneclock.move", XrmoptionNoArg, (caddr_t) "off"},
{(char *) "-pulsating", (char *) ".toneclock.pulsating", XrmoptionNoArg, (caddr_t) "on"},
{(char *) "+pulsating", (char *) ".toneclock.pulsating", XrmoptionNoArg, (caddr_t) "off"}
};
static argtype vars[] =
{
{(void *) & fill, (char *) "fill", (char *) "Fill", (char *) DEF_FILL, t_Int},
{(void *) & cycle_p, (char *) "cycle", (char *) "Cycle", (char *) DEF_CYCLE, t_Bool},
{(void *) & original, (char *) "original", (char *) "Original", (char *) DEF_ORIGINAL, t_Bool},
{(void *) & move_clock, (char *) "move", (char *) "Move", (char *) DEF_MOVE, t_Bool},
{(void *) & pulsating, (char *) "pulsating", (char *) "Pulsating", (char *) DEF_PULSATING, t_Bool}
};
static OptionStruct desc[] =
{
{(char *) "-fill num", (char *) "polygon filling chance in %"},
{(char *) "-/+cycle", (char *) "turn on/off colour cycling"},
{(char *) "-/+original", (char *) "turn on/off displaying original clock only"},
{(char *) "-/+move", (char *) "turn on/off moving small clocks"},
{(char *) "-/+pulsating", (char *) "turn on/off pulsating clock"}
};
ModeSpecOpt toneclock_opts =
{sizeof opts / sizeof opts[0], opts, sizeof vars / sizeof vars[0], vars, desc};
#ifdef USE_MODULES
ModStruct toneclock_description =
{"toneclock", "init_toneclock", "draw_toneclock", "release_toneclock",
"refresh_toneclock", "init_toneclock", (char *) NULL, &toneclock_opts,
60000, -20, 200, -1000, 64, 1.0, "",
"Shows Peter Schat's toneclock", 0, NULL};
#endif
#define PI_RAD (M_PI / 180.0)
typedef struct {
unsigned long colour;
float angle, velocity , radius;
int num_point , num_point1;
int* point_numbers;
Bool draw;
} toneclockhour;
typedef struct {
ModeInfo *mi;
Pixmap dbuf;
GC dbuf_gc;
GC gc;
Colormap cmap;
XColor *colors;
Bool painted;
int win_width, win_height, num_hour, x0, y0 , fill;
float angle , velocity , radius , phase , ph_vel;
float vx , vy , anglex , angley , max_radius;
int a_x , a_y;
int ncolors;
Bool cycle_p, mono_p, no_colors, original, pulsating , moving;
Bool randomhour;
unsigned long blackpixel, whitepixel, fg, bg;
int direction;
int hexadecimal_clock[512];
toneclockhour *hour;
} toneclockstruct;
static int original_clock[12][16] = {
{ 1 , 1 , 5 , 9 , 2 , 2 , 6 , 10 , 3 , 3 , 7 , 11 , 4 , 4 , 8 , 12 } ,
{ 1 , 1 , 2 , 3 , 4 , 4 , 5 , 6 , 7 , 7 , 8 , 9 , 10 , 10 , 11 , 12 } ,
{ 1 , 1 , 2 , 4 , 3 , 3 , 5 , 6 , 7 , 7 , 8 , 10 , 9 , 9 , 11 , 12 } ,
{ 1 , 1 , 2 , 5 , 3 , 3 , 4 , 7 , 6 , 6 , 9 , 10 , 8 , 8 , 11 , 12 } ,
{ 1 , 1 , 2 , 6 , 3 , 3 , 4 , 8 , 5 , 5 , 9 , 10 , 7 , 7 , 11 , 12 } ,
{ 1 , 1 , 2 , 7 , 3 , 3 , 8 , 9 , 4 , 4 , 5 , 10 , 6 , 6 , 11 , 12 } ,
{ 1 , 1 , 3 , 5 , 2 , 2 , 10 , 12 , 4 , 4 , 6 , 8 , 7 , 7 , 9 , 11 } ,
{ 1 , 1 , 3 , 6 , 2 , 2 , 4 , 11 , 5 , 5 , 8 , 10 , 7 , 7 , 9 , 12 } ,
{ 1 , 1 , 3 , 7 , 2 , 2 , 4 , 8 , 5 , 5 , 10 , 11 , 6 , 6 , 10 , 12 } ,
{ 1 , 1 , 3 , 8 , 2 , 2 , 7 , 9 , 4 , 4 , 6 , 11 , 5 , 5 , 10 , 12 } ,
{ 1 , 4 , 7 , 10 , 2 , 5 , 8 , 11 , 3 , 6 , 9 , 12 , 1 , 1 , 1 , 1 } ,
{ 1 , 1 , 4 , 8 , 2 , 2 , 7 , 11 , 3 , 3 , 6 , 10 , 5 , 5 , 9 , 12 }
};
static toneclockstruct *toneclocks = (toneclockstruct *) NULL;
static void
toneclock_drawhour(ModeInfo * mi, toneclockhour * hour0 ,
int x0 , int y0 )
{
Display *display = MI_DISPLAY(mi);
toneclockstruct *tclock;
int i;
#ifdef NO_DBUF
Window drawable = MI_WINDOW(mi);
#else
#define drawable (Drawable) tclock->dbuf
#endif
tclock = &toneclocks[MI_SCREEN(mi)];
for (i = 0; i < hour0->num_point1; i = i + 4)
{
int x , y , x1 , y1 , x2 , y2 , x3 , y3;
x = (int) (hour0->radius * sin( hour0->angle + PI_RAD *
hour0->point_numbers[ i ] * 360.0 /
hour0->num_point ) ) + x0;
y = (int) (hour0->radius * cos( hour0->angle + PI_RAD *
hour0->point_numbers[ i ] * 360.0 /
hour0->num_point ) ) + y0;
x1 = (int) (hour0->radius * sin( hour0->angle + PI_RAD *
hour0->point_numbers[ i + 1 ] * 360.0 /
hour0->num_point ) ) + x0;
y1 = (int) (hour0->radius * cos( hour0->angle + PI_RAD *
hour0->point_numbers[ i + 1 ] * 360.0 /
hour0->num_point ) ) + y0;
x2 = (int) (hour0->radius * sin( hour0->angle + PI_RAD *
hour0->point_numbers[ i + 2 ] * 360.0 /
hour0->num_point ) ) + x0;
y2 = (int) (hour0->radius * cos( hour0->angle + PI_RAD *
hour0->point_numbers[ i + 2 ] * 360.0 /
hour0->num_point ) ) + y0;
x3 = (int) (hour0->radius * sin( hour0->angle + PI_RAD *
hour0->point_numbers[ i + 3 ] * 360.0 /
hour0->num_point ) ) + x0;
y3 = (int) (hour0->radius * cos( hour0->angle + PI_RAD *
hour0->point_numbers[ i + 3 ] * 360.0 /
hour0->num_point ) ) + y0;
if ( hour0->draw )
{
XDrawLine(display, drawable, tclock->gc, x , y , x1 , y1 );
XDrawLine(display, drawable, tclock->gc, x1 , y1 , x2 , y2 );
XDrawLine(display, drawable, tclock->gc, x2 , y2 , x3 , y3 );
XDrawLine(display, drawable, tclock->gc, x , y , x3 , y3 );
}
else
{
XPoint xy[4];
xy[0].x = x;
xy[0].y = y;
xy[1].x = x1;
xy[1].y = y1;
xy[2].x = x2;
xy[2].y = y2;
xy[3].x = x3;
xy[3].y = y3;
XFillPolygon(display, drawable, tclock->gc, xy, 4 , Convex,
CoordModeOrigin);
}
}
}
static void
free_hour(toneclockstruct *tclock)
{
if (tclock->hour != NULL) {
free(tclock->hour);
tclock->hour = (toneclockhour *) NULL;
}
}
static void
free_toneclock(Display *display, toneclockstruct *tclock)
{
ModeInfo *mi = tclock->mi;
if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) {
MI_WHITE_PIXEL(mi) = tclock->whitepixel;
MI_BLACK_PIXEL(mi) = tclock->blackpixel;
#ifndef STANDALONE
MI_FG_PIXEL(mi) = tclock->fg;
MI_BG_PIXEL(mi) = tclock->bg;
#endif
if (tclock->colors != NULL) {
if (tclock->ncolors && !tclock->no_colors)
free_colors(display, tclock->cmap, tclock->colors, tclock->ncolors);
free(tclock->colors);
tclock->colors = (XColor *) NULL;
}
if (tclock->cmap != None) {
XFreeColormap(display, tclock->cmap);
tclock->cmap = None;
}
}
if (tclock->gc != None) {
XFreeGC(display, tclock->gc);
tclock->gc = None;
}
free_hour(tclock);
#ifndef NO_DBUF
if (tclock->dbuf != None) {
XFreePixmap(display, tclock->dbuf);
tclock->dbuf = None;
}
if (tclock->dbuf_gc != None) {
XFreeGC(display, tclock->dbuf_gc);
tclock->dbuf_gc = None;
}
#endif
}
#ifndef STANDALONE
extern char *background;
extern char *foreground;
#endif
void
init_toneclock(ModeInfo * mi)
{
Display *display = MI_DISPLAY(mi);
Window window = MI_WINDOW(mi);
int i, size_hour, istart;
toneclockstruct *tclock;
/* initialize */
if (toneclocks == NULL) {
if ((toneclocks = (toneclockstruct *) calloc(MI_NUM_SCREENS(mi),
sizeof (toneclockstruct))) == NULL)
return;
}
tclock = &toneclocks[MI_SCREEN(mi)];
tclock->mi = mi;
if (tclock->gc == None) {
if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) {
XColor color;
#ifndef STANDALONE
tclock->fg = MI_FG_PIXEL(mi);
tclock->bg = MI_BG_PIXEL(mi);
#endif
tclock->blackpixel = MI_BLACK_PIXEL(mi);
tclock->whitepixel = MI_WHITE_PIXEL(mi);
if ((tclock->cmap = XCreateColormap(display, window,
MI_VISUAL(mi), AllocNone)) == None) {
free_toneclock(display, tclock);
return;
}
XSetWindowColormap(display, window, tclock->cmap);
(void) XParseColor(display, tclock->cmap, "black", &color);
(void) XAllocColor(display, tclock->cmap, &color);
MI_BLACK_PIXEL(mi) = color.pixel;
(void) XParseColor(display, tclock->cmap, "white", &color);
(void) XAllocColor(display, tclock->cmap, &color);
MI_WHITE_PIXEL(mi) = color.pixel;
#ifndef STANDALONE
(void) XParseColor(display, tclock->cmap, background, &color);
(void) XAllocColor(display, tclock->cmap, &color);
MI_BG_PIXEL(mi) = color.pixel;
(void) XParseColor(display, tclock->cmap, foreground, &color);
(void) XAllocColor(display, tclock->cmap, &color);
MI_FG_PIXEL(mi) = color.pixel;
#endif
tclock->colors = (XColor *) NULL;
tclock->ncolors = 0;
}
if ((tclock->gc = XCreateGC(display, MI_WINDOW(mi),
(unsigned long) 0, (XGCValues *) NULL)) == None) {
free_toneclock(display, tclock);
return;
}
}
/* Clear Display */
MI_CLEARWINDOW(mi);
tclock->painted = False;
XSetFunction(display, tclock->gc, GXxor);
/*Set up toneclock data */
if (MI_IS_FULLRANDOM(mi)) {
if (NRAND(10))
tclock->original = False;
else
tclock->original = True;
} else {
tclock->original = original;
}
tclock->direction = (LRAND() & 1) ? 1 : -1;
tclock->win_width = MI_WIDTH(mi);
tclock->win_height = MI_HEIGHT(mi);
if (tclock->hour != NULL)
free_hour(tclock);
if ( tclock->original )
{
tclock->num_hour = 12;
}
else
{
tclock->num_hour = MI_COUNT(mi);
}
tclock->x0 = tclock->win_width / 2;
tclock->y0 = tclock->win_height / 2;
if (tclock->num_hour == 0) {
tclock->num_hour = DEF_NUM_hour;
} else if (tclock->num_hour < 0) {
tclock->num_hour = NRAND(-tclock->num_hour) + 1;
}
if ( tclock->num_hour < 12 )
istart = NRAND( 12 - tclock->num_hour );
else
istart = 0;
if ((tclock->hour = (toneclockhour *) calloc(tclock->num_hour,
sizeof (toneclockhour))) == NULL) {
free_toneclock(display, tclock);
return;
}
if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) {
/* Set up colour map */
if (tclock->colors != NULL) {
if (tclock->ncolors && !tclock->no_colors)
free_colors(display, tclock->cmap, tclock->colors, tclock->ncolors);
free(tclock->colors);
tclock->colors = (XColor *) NULL;
}
tclock->ncolors = MI_NCOLORS(mi);
if (tclock->ncolors < 2)
tclock->ncolors = 2;
if (tclock->ncolors <= 2)
tclock->mono_p = True;
else
tclock->mono_p = False;
if (tclock->mono_p)
tclock->colors = (XColor *) NULL;
else
if ((tclock->colors = (XColor *) malloc(sizeof (*tclock->colors) *
(tclock->ncolors + 1))) == NULL) {
free_toneclock(display, tclock);
return;
}
tclock->cycle_p = has_writable_cells(mi);
if (tclock->cycle_p) {
if (MI_IS_FULLRANDOM(mi)) {
if (!NRAND(8))
tclock->cycle_p = False;
else
tclock->cycle_p = True;
} else {
tclock->cycle_p = cycle_p;
}
}
if (!tclock->mono_p) {
if (!(LRAND() % 10))
make_random_colormap(
#ifdef STANDALONE
MI_DISPLAY(mi), MI_WINDOW(mi),
#else
mi,
#endif
tclock->cmap, tclock->colors, &tclock->ncolors,
True, True, &tclock->cycle_p);
else if (!(LRAND() % 2))
make_uniform_colormap(
#ifdef STANDALONE
MI_DISPLAY(mi), MI_WINDOW(mi),
#else
mi,
#endif
tclock->cmap, tclock->colors, &tclock->ncolors,
True, &tclock->cycle_p);
else
make_smooth_colormap(
#ifdef STANDALONE
MI_DISPLAY(mi), MI_WINDOW(mi),
#else
mi,
#endif
tclock->cmap, tclock->colors, &tclock->ncolors,
True, &tclock->cycle_p);
}
XInstallColormap(display, tclock->cmap);
if (tclock->ncolors < 2) {
tclock->ncolors = 2;
tclock->no_colors = True;
} else
tclock->no_colors = False;
if (tclock->ncolors <= 2)
tclock->mono_p = True;
if (tclock->mono_p)
tclock->cycle_p = False;
}
#ifndef NO_DBUF
if (tclock->dbuf != None)
XFreePixmap(display, tclock->dbuf);
tclock->dbuf = XCreatePixmap(display, window,
tclock->win_width,
tclock->win_height,
MI_DEPTH(mi));
/* Allocation checked */
if (tclock->dbuf != None) {
XGCValues gcv;
gcv.foreground = 0;
gcv.background = 0;
gcv.graphics_exposures = False;
gcv.function = GXcopy;
if (tclock->dbuf_gc != None)
XFreeGC(display, tclock->dbuf_gc);
if ((tclock->dbuf_gc = XCreateGC(display, (Drawable) tclock->dbuf,
GCForeground | GCBackground | GCGraphicsExposures | GCFunction,
&gcv)) == None) {
XFreePixmap(display, tclock->dbuf);
tclock->dbuf = None;
} else {
XFillRectangle(display, (Drawable) tclock->dbuf, tclock->dbuf_gc,
0, 0, tclock->win_width, tclock->win_height);
XSetBackground(display, MI_GC(mi), MI_BLACK_PIXEL(mi));
XSetFunction(display, MI_GC(mi), GXcopy);
}
}
#endif
tclock->angle = NRAND(360) * PI_RAD;
tclock->velocity = (NRAND(7) - 3) * PI_RAD;
size_hour = MIN( tclock->win_width , tclock->win_height) / 3;
tclock->pulsating = False;
tclock->moving = False;
tclock->anglex = 0.0;
tclock->angley = 0.0;
tclock->fill = 0;
tclock->radius = size_hour;
tclock->max_radius =0.0;
if ( ( !tclock->original && NRAND( 15 ) == 3 ) || tclock->num_hour > 12 )
tclock->randomhour = True;
else
tclock->randomhour = False;
if ( !tclock->original && tclock->win_width > 20 )
{
if ( abs( MI_SIZE(mi) ) > size_hour ) {
if ( MI_SIZE( mi ) < 0 )
{
size_hour = -size_hour;
}
}
else
{
size_hour = MI_SIZE(mi);
}
if ( size_hour < 0 )
{
tclock->radius = MIN(NRAND( size_hour - 10) + 10,
tclock->radius );
}
else
{
tclock->radius = MIN( size_hour , tclock->radius );
}
if ( MI_IS_FULLRANDOM( mi ) )
{
if ( NRAND(2) )
tclock->pulsating = True;
else
tclock->pulsating = False;
tclock->fill = NRAND( 101 );
}
else
{
tclock->pulsating = pulsating;
tclock->fill = fill;
}
}
tclock->phase = 0.0;
if ( tclock->pulsating )
tclock->ph_vel = (NRAND(7) - 3) * PI_RAD;
for (i = 0; i < tclock->num_hour; i++) {
toneclockhour *hour0;
hour0 = &tclock->hour[i];
if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) {
if (tclock->ncolors > 2)
hour0->colour = NRAND(tclock->ncolors - 2) + 2;
else
hour0->colour = 1; /* Just in case */
XSetForeground(display, tclock->gc, tclock->colors[hour0->colour].pixel);
} else {
if (MI_NPIXELS(mi) > 2)
hour0->colour = MI_PIXEL(mi, NRAND(MI_NPIXELS(mi)));
else
hour0->colour = 1; /*Xor'red so WHITE may not be appropriate */
XSetForeground(display, tclock->gc, hour0->colour);
}
hour0->angle = NRAND(360) * PI_RAD;
hour0->velocity = (NRAND(7) - 3) * PI_RAD;
hour0->radius = tclock->radius / 5.0;
tclock->max_radius = MAX( tclock->max_radius , hour0->radius );
hour0->num_point = 12;
hour0->num_point1 = 16;
if ( tclock->randomhour )
{
int j;
hour0->point_numbers = tclock->hexadecimal_clock + i *
hour0->num_point1;
if ( NRAND( 14 ) == 4 )
{
for (j = 0; j < ( hour0->num_point1 / 4 ) - 1 ; j++)
{
hour0->point_numbers[ j * 4 ] = NRAND( 12 ) + 1;
hour0->point_numbers[ j * 4 + 1 ] = NRAND( 12 )
+ 1;
hour0->point_numbers[ j * 4 + 2 ] = NRAND( 12 )
+ 1;
hour0->point_numbers[ j * 4 + 3 ] = NRAND( 12 )
+ 1;
}
hour0->point_numbers[ hour0->num_point1 / 4 ] = 1;
hour0->point_numbers[ 1 + hour0->num_point1 / 4 ] =
1;
hour0->point_numbers[ 2 + hour0->num_point1 / 4 ] =
1;
hour0->point_numbers[ 3 + hour0->num_point1 / 4 ] =
1;
}
else
{
for (j = 0; j < hour0->num_point1 / 4 ; j++)
{
hour0->point_numbers[ j * 4 ] = NRAND( 12 ) + 1;
hour0->point_numbers[ j * 4 + 1 ] =
hour0->point_numbers[ j * 4 ];
hour0->point_numbers[ j * 4 + 2 ] = NRAND( 12 )
+ 1;
hour0->point_numbers[ j * 4 + 3 ] = NRAND( 12 )
+ 1;
}
}
}
else
hour0->point_numbers = original_clock[i+istart];
if ( NRAND( 100 ) >= tclock->fill )
hour0->draw = True;
else
hour0->draw = False;
#ifdef NO_DBUF
{
int x0 , y0;
x0 = (int) (tclock->radius * sin( -tclock->angle - PI_RAD * i *
360.0 / tclock->num_hour ) *
0.5 * ( 1 + cos( tclock->phase ) ) + tclock->x0 +
tclock->a_x * sin( tclock->anglex ) );
y0 = (int) (tclock->radius * cos( -tclock->angle - PI_RAD * i *
360.0 / tclock->num_hour ) *
0.5 * ( 1 + cos( tclock->phase ) ) + tclock->y0 +
tclock->a_y * sin( tclock->angley ) );
toneclock_drawhour(mi , hour0 , x0 , y0 );
}
#endif
}
tclock->a_x = 0;
tclock->a_y = 0;
if ( !tclock->original && tclock->win_width > 20 )
{
if ( tclock->radius < MIN( tclock->win_width , tclock->win_height) /
4 )
{
if ( MI_IS_FULLRANDOM( mi ) )
{
if ( NRAND(2) )
tclock->moving = True;
}
else
{
tclock->moving = move_clock;
}
if ( tclock->moving )
{
tclock->a_x = (int) floor( ( tclock->win_width / 2 ) - 1.05 *
( tclock->radius + tclock->max_radius )
);
tclock->a_y = (int) floor( ( tclock->win_height / 2 ) - 1.05 *
( tclock->radius + tclock->max_radius )
);
tclock->vx = (NRAND(15) - 7) * PI_RAD;
tclock->vy = (NRAND(15) - 7) * PI_RAD;
}
}
}
XFlush(display);
XSetFunction(display, tclock->gc, GXcopy);
}
void
draw_toneclock(ModeInfo * mi)
{
Display *display = MI_DISPLAY(mi);
Window window = MI_WINDOW(mi);
int i;
toneclockstruct *tclock;
if (toneclocks == NULL)
return;
tclock = &toneclocks[MI_SCREEN(mi)];
if (tclock->hour == NULL)
return;
if (tclock->no_colors) {
free_toneclock(display, tclock);
init_toneclock(mi);
return;
}
XSetFunction(display, tclock->gc, GXxor);
#ifndef NO_DBUF
XSetForeground(display,tclock->dbuf_gc,MI_BLACK_PIXEL(mi));
XFillRectangle(display, (Drawable) tclock->dbuf, tclock->dbuf_gc,
0, 0, tclock->win_width, tclock->win_height);
#endif
tclock->painted = True;
MI_IS_DRAWN(mi) = True;
/* Rotate colours */
if (tclock->cycle_p) {
rotate_colors(display, tclock->cmap, tclock->colors, tclock->ncolors,
tclock->direction);
if (!(LRAND() % 1000))
tclock->direction = -tclock->direction;
}
for (i = 0; i < tclock->num_hour; i++) {
toneclockhour *hour0;
int x0 , y0;
x0 = (int) (tclock->radius * sin( -tclock->angle - PI_RAD * i *
360.0 / tclock->num_hour ) *
0.5 * ( 1 + cos( tclock->phase ) ) + tclock->x0 +
tclock->a_x * sin( tclock->anglex ) );
y0 = (int) (tclock->radius * cos( -tclock->angle - PI_RAD * i *
360.0 / tclock->num_hour ) *
0.5 * ( 1 + cos( tclock->phase ) ) + tclock->y0 +
tclock->a_y * sin( tclock->angley ) );
hour0 = &tclock->hour[i];
if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) {
XSetForeground(display, tclock->gc, tclock->colors[hour0->colour].pixel);
} else {
XSetForeground(display, tclock->gc, hour0->colour);
}
toneclock_drawhour(mi, hour0 , x0 , y0);
hour0->velocity += ((float) NRAND(1001) - 500.0) / 200000.0;
hour0->angle += hour0->velocity;
}
tclock->velocity += ((float) NRAND(1001) - 500.0) / 200000.0;
tclock->angle += tclock->velocity;
if ( tclock->pulsating )
tclock->phase += tclock->ph_vel;
if ( tclock->moving )
{
tclock->anglex += tclock->vx;
tclock->angley += tclock->vy;
}
#ifdef NO_DBUF
for (i = 0; i < tclock->num_hour; i++) {
toneclockhour *hour0;
int x0 , y0;
x0 = (int) (tclock->radius * sin( -tclock->angle - PI_RAD * i *
360.0 / tclock->num_hour ) *
0.5 * ( 1 + cos( tclock->phase ) ) + tclock->x0 +
tclock->a_x * sin( tclock->anglex ) );
y0 = (int) (tclock->radius * cos( -tclock->angle - PI_RAD * i *
360.0 / tclock->num_hour ) *
0.5 * ( 1 + cos( tclock->phase ) ) + tclock->y0 +
tclock->a_y * sin( tclock->angley ) );
hour0 = &tclock->hour[i];
if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) {
XSetForeground(display, tclock->gc, tclock->colors[hour0->colour].pixel);
} else {
XSetForeground(display, tclock->gc, hour0->colour);
}
toneclock_drawhour(mi, hour0 , x0 , y0);
}
#else
XFlush(display);
XCopyArea (display, (Drawable) tclock->dbuf, window, tclock->dbuf_gc, 0, 0,
tclock->win_width, tclock->win_height, 0, 0);
XFlush(display);
XSetForeground(display,tclock->dbuf_gc,MI_BLACK_PIXEL(mi));
XFillRectangle(display, (Drawable) tclock->dbuf, tclock->dbuf_gc,
0, 0, tclock->win_width, tclock->win_height);
#endif
XSetFunction(display, tclock->gc, GXcopy);
}
void
refresh_toneclock(ModeInfo * mi)
{
toneclockstruct *tclock;
if (toneclocks == NULL)
return;
tclock = &toneclocks[MI_SCREEN(mi)];
if (tclock->hour == NULL)
return;
if (!tclock->painted)
return;
MI_CLEARWINDOW(mi);
#ifdef NO_DBUF
{
Display *display = MI_DISPLAY(mi);
int i;
XSetFunction(display, tclock->gc, GXxor);
for (i = 0; i < tclock->num_hour; i++) {
toneclockhour *hour0;
int x0 , y0;
x0 = (int) (tclock->radius * sin( -tclock->angle - PI_RAD * i *
360.0 / tclock->num_hour ) +
tclock->x0 + tclock->a_x * sin( tclock->anglex ) );
y0 = (int) (tclock->radius * cos( -tclock->angle - PI_RAD * i *
360.0 / tclock->num_hour ) +
tclock->y0 + tclock->a_y * sin( tclock->angley ) );
hour0 = &tclock->hour[i];
if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) {
XSetForeground(display, tclock->gc, tclock->colors[hour0->colour].pixel);
} else {
XSetForeground(display, tclock->gc, hour0->colour);
}
toneclock_drawhour(mi, hour0 , x0 , y0 );
}
XSetFunction(display, tclock->gc, GXcopy);
}
#endif
}
void
release_toneclock(ModeInfo * mi)
{
if (toneclocks != NULL) {
int screen;
for (screen = 0; screen < MI_NUM_SCREENS(mi); screen++)
free_toneclock(MI_DISPLAY(mi), &toneclocks[screen]);
free(toneclocks);
toneclocks = (toneclockstruct *) NULL;
}
}
#endif /* MODE_toneclock */
|