3 /* Copyright (C) 2002 Brad Jorsch <anomie@users.sourceforge.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 /* One-line algorithm from http://www.moonstick.com/moon_phase_emergency.htm
21 * It's a bit rough, but it works well enough */
24 # if TIME_WITH_SYS_TIME
25 # include <sys/time.h>
29 # include <sys/time.h>
44 #include "wmgeneral/wmgeneral-x11.h"
46 static double fpart(double t
){
50 double calc_moon(int month
, int day
, int year
, int hm
){
64 /* This next line is the algorithm. */
65 p
=fpart(((t
/86400.0-11323.0)*850.0+5130.5769)/25101.0);
66 if(p
>.5) return -.5+cos(2*PI
*p
)/2;
67 return .5-cos(2*PI
*p
)/2;
71 #define darkside 0.19921875
72 #define lightside (1-0.19921875)
74 static int widths
[]={ 7, 11, 13, 15, 15, 17, 17, 17, 17, 17, 17, 17, 15, 15, 13, 11, 7, -1 };
79 /* Duplicates quite a bit of code from combineWithOpacity for speed */
80 void copySunMoon(int x
, int y
, double percent
){
82 unsigned int w
, h
, bar
;
85 int rmask
, gmask
, bmask
;
87 int xx
, terminator
, oflag
;
92 copyPixmapArea(164, 64, 26, 25, x
, y
);
96 XGetGeometry(display
, wmgen
.pixmap
, &baz
, &foo
, &foo
, &w
, &h
, &bar
, &bar
);
97 pix
=XGetImage(display
, wmgen
.pixmap
, 0, 0, w
, h
, AllPlanes
, ZPixmap
);
99 if (pix
->depth
== DefaultDepth(display
, screen
)) {{
100 Visual
*visual
=DefaultVisual(display
, screen
);
101 rmask
= visual
->red_mask
;
102 gmask
= visual
->green_mask
;
103 bmask
= visual
->blue_mask
;
105 rmask
= pix
->red_mask
;
106 gmask
= pix
->green_mask
;
107 bmask
= pix
->blue_mask
;
112 if(flag
) percent
=-percent
;
113 for(h
=0; widths
[h
]>0; h
++){
114 xx
=(maxwidth
-widths
[h
])>>1;
117 terminator
=widths
[h
]*percent
;
120 terminator
=widths
[h
]-widths
[h
]*percent
;
122 frac
=lightside
*fpart(widths
[h
]*percent
)+darkside
;
123 for(w
=0; w
<widths
[h
]; w
++){
124 spixel
=XGetPixel(pix
, 168+xx
+w
, 93+h
);
127 XPutPixel(pix
, x
+xx
+w
, y
+h
,
128 (((unsigned long)((spixel
&rmask
)*frac
))&rmask
) |
129 (((unsigned long)((spixel
&gmask
)*frac
))&gmask
) |
130 (((unsigned long)((spixel
&bmask
)*frac
))&bmask
));
132 XPutPixel(pix
, x
+xx
+w
, y
+h
, spixel
);
134 XPutPixel(pix
, x
+xx
+w
, y
+h
,
135 (((unsigned long)((spixel
&rmask
)*darkside
))&rmask
) |
136 (((unsigned long)((spixel
&gmask
)*darkside
))&gmask
) |
137 (((unsigned long)((spixel
&bmask
)*darkside
))&bmask
));
142 XPutImage(display
, wmgen
.pixmap
, NormalGC
, pix
, 0, 0, 0, 0, pix
->width
, pix
->height
);
148 void copySunMoon(int x
, int y
, double percent
){
155 copyPixmapArea(164, 64, 26, 25, x
, y
);
159 combineWithOpacity(164, 89, 26, 25, x
, y
, 51);
162 if(flag
) percent
=-percent
;
165 frac
=(widths
[h
]*percent
-w
)*100;
166 if(flag
) xx
=(17-widths
[h
])/2;
167 else xx
=(17+widths
[h
])/2-w
;
168 copyPixmapArea(141+xx
, 93+h
, w
, 1, x
+xx
, y
+h
);
169 copyPixmapArea(141+xx
, 109-h
, w
, 1, x
+xx
, y
+16-h
);
171 combineWithOpacity(141+xx
+w
, 93+h
, 1, 1, x
+xx
+w
, y
+h
, frac
);
172 combineWithOpacity(141+xx
+w
, 109-h
, 1, 1, x
+xx
+w
, y
+16-h
, frac
);
174 combineWithOpacity(141+xx
-1, 93+h
, 1, 1, x
+xx
-1, y
+h
, frac
);
175 combineWithOpacity(141+xx
-1, 109-h
, 1, 1, x
+xx
-1, y
+16-h
, frac
);