summarylogtreecommitdiffstats
path: root/xmatrix-color.diff
blob: 13a74593b138a76fe8c4a06d3fc78264cf39b98c (plain)
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
--- hacks/xmatrix.c	2018-04-06 16:44:02.000000000 -0500
+++ hacks/xmatrix.c.mod	2018-06-17 11:54:17.229608887 -0500
@@ -219,6 +219,8 @@
 static void
 load_images_1 (Display *dpy, m_state *state, int which)
 {
+  /* Get the -color-shift argument. */
+  const char *shift_text = get_string_resource(dpy, "colorShift", "String");
   const unsigned char *png = 0;
   unsigned long size = 0;
   if (which == 1)
@@ -236,8 +238,8 @@
         png = matrix2_png, size = sizeof(matrix2_png);
     }
   state->images[which] =
-    image_data_to_pixmap (state->dpy, state->window, png, size,
-                          &state->image_width, &state->image_height, 0);
+    image_data_to_pixmap_shift (state->dpy, state->window, png, size,
+                          &state->image_width, &state->image_height, 0, shift_text);
 }
 
 
@@ -1049,26 +1051,38 @@
       }
 }
 
-
 static int
 densitizer (m_state *state)
 {
-  /* Horrid kludge that converts percentages (density of screen coverage)
-     to the parameter that actually controls this.  I got this mapping
-     empirically, on a 1024x768 screen.  Sue me. */
-  if      (state->density < 10) return 85;
-  else if (state->density < 15) return 60;
-  else if (state->density < 20) return 45;
-  else if (state->density < 25) return 25;
-  else if (state->density < 30) return 20;
-  else if (state->density < 35) return 15;
-  else if (state->density < 45) return 10;
-  else if (state->density < 50) return 8;
-  else if (state->density < 55) return 7;
-  else if (state->density < 65) return 5;
-  else if (state->density < 80) return 3;
-  else if (state->density < 90) return 2;
-  else return 1;
+  /* Best fit curve to replace old table.
+   * Now you can twiddle single % values
+   * and its technically doing something.
+   * y = a * exp(b*x)
+   * See 'densitizer.sce' for comparison. */
+
+  /* Declare variables */
+  double a, b;
+  int y;
+  int x = state->density;
+
+  /* Clean input */
+  if (x > 100) {
+	  x = 100;
+  }
+  else if (x < 1) {
+	  x = 1;
+  }
+
+  /* Set exp function params */
+  a=211.538187957;
+  b=-0.0488730165089;
+
+  /* Calculate result, used in xmatrix_init()
+   * and hack_matrix() */
+  y=a*exp(b*x);
+
+  /*printf("\nDensitizer. x=%d, y=%d", x, y);*/
+  return(y);
 }
 
 
@@ -1823,6 +1837,7 @@
   "*usePty:                False",
   "*program:		   xscreensaver-text --latin1",
   "*geometry:		   960x720",
+  ".colorShift:     green",
   0
 };
 
@@ -1850,6 +1865,7 @@
   { "-pipe",	        ".usePipe",		XrmoptionNoArg, "True" },
   { "-no-pipe",	        ".usePipe",		XrmoptionNoArg, "False" },
   { "-program",	        ".program",		XrmoptionSepArg, 0 },
+  { "-color-shift",	        ".colorShift",		XrmoptionSepArg, 0 },
   { 0, 0, 0, 0 }
 };
 
--- hacks/config/xmatrix.xml	2016-04-07 21:15:38.000000000 -0500
+++ hacks/config/xmatrix.xml.mod	2018-06-17 11:54:17.229608887 -0500
@@ -25,6 +25,16 @@
      <option id="top"    _label="Slider algorithm"    arg-set="-insert top"/>
      <option id="bottom" _label="Expansion algorithm" arg-set="-insert bottom"/>
    </select>
+
+   <select id="color">
+	   <option id="color_green" _label="Green"/>
+     <option id="color_blue" _label="Blue"  arg-set="-color-shift blue"/>
+     <option id="color_red" _label="Red"  arg-set="-color-shift red"/>
+     <option id="color_yellow" _label="Yellow"  arg-set="-color-shift yellow"/>
+     <option id="color_aqua" _label="Aqua"  arg-set="-color-shift aqua"/>
+     <option id="color_white" _label="White"  arg-set="-color-shift White"/>
+     <option id="color_grey" _label="Grey"  arg-set="-color-shift grey"/>
+   </select>
   </hgroup>
 
   <hgroup>
--- hacks/xmatrix.man	2018-04-08 12:56:39.000000000 -0500
+++ hacks/xmatrix.man.mod	2018-06-17 11:54:17.229608887 -0500
@@ -26,6 +26,7 @@
 [\-mode \fImode\fP]
 [\-phone \fInumber\fP]
 [\-fps]
+[\-color\-shift "color"]
 .SH DESCRIPTION
 The \fIxmatrix\fP program draws the 2D "digital rain" effect, as seen on
 the computer monitors in the Wachowski brothers' film, "The Matrix".
@@ -120,6 +121,12 @@
 xmatrix -ascii -program 'ps -eo comm | rev'
 xmatrix -program 'od -txC -w6 /dev/random'
 xmatrix -program 'cat /dev/random'
+
+.TP 8
+.B \-color-shift
+Specify a simple color shift to one of:
+red, blue, green, purple, yellow, aqua, white, grey
+
 .EE
 .SH ENVIRONMENT
 .PP
--- hacks/ximage-loader.c	2018-04-07 22:05:20.000000000 -0500
+++ hacks/ximage-loader.c.mod	2018-06-17 11:54:17.229608887 -0500
@@ -503,7 +503,8 @@
 make_pixmap (Display *dpy, Window window,
              const char *filename,
              const unsigned char *image_data, unsigned long data_size,
-             int *width_ret, int *height_ret, Pixmap *mask_ret)
+             int *width_ret, int *height_ret, Pixmap *mask_ret,
+             const char * shift_text)
 {
   XWindowAttributes xgwa;
   XImage *in, *out, *mask = 0;
@@ -576,6 +577,44 @@
         unsigned char b = (p >> cbpos) & 0xFF;
         unsigned char g = (p >> cgpos) & 0xFF;
         unsigned char r = (p >> crpos) & 0xFF;
+
+        if (!strcasecmp(shift_text, "yellow"))
+    		{
+    			r = g;
+    		}
+    		else if (!strcasecmp(shift_text, "red"))
+    		{
+    			unsigned char tmp = r;
+          r = g;
+          g = tmp;
+    		}
+    		else if (!strcasecmp(shift_text, "blue"))
+    		{
+          unsigned char tmp = b;
+          b = g;
+          g = tmp;
+    		}
+    		else if (!strcasecmp(shift_text, "purple"))
+    		{
+          unsigned char tmp = r;
+          r = g;
+          b = g;
+          g = tmp;
+    		}
+    		else if (!strcasecmp(shift_text, "aqua"))
+    		{
+          b = g;
+    		}
+    		else if (!strcasecmp(shift_text, "white"))
+    		{
+          r = g;
+          b = g;
+    		}
+    		else if (!strcasecmp(shift_text, "grey"))
+    		{
+    			g = r;
+    		}
+
         XPutPixel (out, x, y, ((r << srpos) |
                                (g << sgpos) |
                                (b << sbpos) |
@@ -638,13 +677,23 @@
 
 
 Pixmap
-image_data_to_pixmap (Display *dpy, Window window, 
+image_data_to_pixmap_shift (Display *dpy, Window window,
+                      const unsigned char *image_data, unsigned long data_size,
+                      int *width_ret, int *height_ret,
+                      Pixmap *mask_ret, const char * shift_text)
+{
+  return make_pixmap (dpy, window, 0, image_data, data_size,
+                      width_ret, height_ret, mask_ret, shift_text);
+}
+
+Pixmap
+image_data_to_pixmap (Display *dpy, Window window,
                       const unsigned char *image_data, unsigned long data_size,
                       int *width_ret, int *height_ret,
                       Pixmap *mask_ret)
 {
   return make_pixmap (dpy, window, 0, image_data, data_size,
-                      width_ret, height_ret, mask_ret);
+                      width_ret, height_ret, mask_ret, "");
 }
 
 Pixmap
@@ -653,7 +702,7 @@
                 Pixmap *mask_ret)
 {
   return make_pixmap (dpy, window, filename, 0, 0,
-                      width_ret, height_ret, mask_ret);
+                      width_ret, height_ret, mask_ret, "");
 }
 
 
--- hacks/ximage-loader.h	2018-03-19 16:54:48.000000000 -0500
+++ hacks/ximage-loader.h.mod	2018-06-17 11:54:17.229608887 -0500
@@ -17,7 +17,13 @@
                               int *width_ret, int *height_ret,
                               Pixmap *mask_ret);
 
-extern Pixmap image_data_to_pixmap (Display *, Window, 
+extern Pixmap image_data_to_pixmap_shift (Display *, Window,
+                                    const unsigned char *image_data,
+                                    unsigned long data_size,
+                                    int *width_ret, int *height_ret,
+                                    Pixmap *mask_ret, const char * shift_text);
+
+extern Pixmap image_data_to_pixmap (Display *, Window,
                                     const unsigned char *image_data,
                                     unsigned long data_size,
                                     int *width_ret, int *height_ret,