1 ; -*- mode: c; tab-width: 4; fill-column: 128 -*-
4 ; Texture, Copyright (c) 2017 Dave Odell <dmo2118@gmail.com>
6 ; Permission to use, copy, modify, distribute, and sell this software and its
7 ; documentation for any purpose is hereby granted without fee, provided that
8 ; the above copyright notice appear in all copies and that both that
9 ; copyright notice and this permission notice appear in supporting
10 ; documentation. No representations are made about the suitability of this
11 ; software for any purpose. It is provided "as is" without express or
14 ; A port of 20 year old QBasic code to a much more modern platform.
197 dcb $00, $00, $00, $00, $00, $00, $00, $00
198 dcb $00, $00, $0b, $0b, $0b, $0b, $0b, $0b
199 dcb $0b, $0b, $0b, $0b, $0b, $0b, $0b, $0b
200 dcb $0c, $0c, $0c, $0c, $0c, $0c, $0c, $0c
201 dcb $0c, $0c, $0c, $0c, $0c, $0c, $0c, $0c
202 dcb $0f, $0f, $0f, $0f, $0f, $0f, $0f, $0f
203 dcb $0f, $0f, $0f, $0f, $0f, $0f, $0f, $0f
204 dcb $0f, $01, $01, $01, $01, $01, $01, $01
205 dcb $01, $01, $01, $01, $01, $01, $01, $01
206 dcb $0f, $0f, $0f, $0f, $0f, $0f, $0f, $0f
207 dcb $0f, $0f, $0f, $0f, $0f, $0f, $0f, $0f
208 dcb $0f, $0c, $0c, $0c, $0c, $0c, $0c, $0c
209 dcb $0c, $0c, $0c, $0c, $0c, $0c, $0c, $0c
210 dcb $0c, $0b, $0b, $0b, $0b, $0b, $0b, $0b
211 dcb $0b, $0b, $0b, $0b, $0b, $0b, $0b, $00
212 dcb $00, $00, $00, $00, $00, $00, $00, $00
213 dcb $00, $00, $00, $00, $00, $00, $00, $00
214 dcb $00, $00, $00, $00, $00, $00, $00, $00
215 dcb $0b, $0b, $0b, $0b, $0b, $0b, $0b, $0b
216 dcb $0b, $0b, $0b, $0b, $0b, $0b, $0b, $0b
217 dcb $0b, $0b, $0b, $0b, $0b, $0b, $05, $05
218 dcb $05, $05, $05, $05, $05, $05, $05, $05
219 dcb $05, $05, $05, $05, $05, $05, $05, $05
220 dcb $0d, $0d, $0d, $0d, $0d, $0d, $0d, $0d
221 dcb $0d, $0d, $0d, $0d, $0d, $0d, $0d, $0d
222 dcb $0d, $05, $05, $05, $05, $05, $05, $05
223 dcb $05, $05, $05, $05, $05, $05, $05, $05
224 dcb $05, $05, $05, $0b, $0b, $0b, $0b, $0b
225 dcb $0b, $0b, $0b, $0b, $0b, $0b, $0b, $0b
226 dcb $0b, $0b, $0b, $0b, $0b, $0b, $0b, $0b
227 dcb $0b, $00, $00, $00, $00, $00, $00, $00
228 dcb $00, $00, $00, $00, $00, $00, $00, $00
233 ; A full-resolution version of the same thing. Not perhaps the most interesting thing to look at.
235 ;#include "screenhack.h"
237 ;#include <inttypes.h>
241 ; unsigned width, height;
244 ; unsigned long palette[128];
247 ; unsigned graininess;
251 ;#define GRAIN(self) (NRAND((self)->graininess * 2 + 1) - (self)->graininess)
253 ;static void _put_line(struct texture *self, Display *dpy, Window window, unsigned y)
256 ; for(x = 0; x != self->width; ++x)
258 ; unsigned c1 = self->row[x];
262 ; XPutPixel(self->image, x, 0, self->palette[(c0 & 63) | ((c1 & 0x80) >> 1)]);
265 ; XPutImage(dpy, window, self->gc, self->image, 0, 0, 0, y, self->width, 1);
267 ; *self->row += GRAIN(self);
269 ; for(x = 1; x != self->width; ++x);
271 ; unsigned avg = self->row[x - 1] + self->row[x];
272 ; self->row[x] = ((avg + ((avg & 2) >> 1)) >> 1) + GRAIN(self);
278 ;static void texture_reshape(Display *dpy, Window window, void *self_raw, unsigned w, unsigned h)
280 ; struct texture *self = self_raw;
283 ; if(w == self->width && h == self->height)
286 ; self->image->bytes_per_line = 0;
287 ; self->image->width = w;
288 ; XInitImage(self->image);
291 ; self->row = malloc(w);
292 ; free(self->image->data);
293 ; self->image->data = malloc(w * self->image->bytes_per_line);
298 ; *self->row = NRAND(0xff);
299 ; for(x = 1; x != self->width; ++x)
300 ; self->row[x] = self->row[x - 1] + GRAIN(self);
302 ; for(y = 0; y != self->height; ++y)
303 ; _put_line(self, dpy, window, y);
306 ;static void *texture_init(Display *dpy, Window window)
308 ; static const XGCValues gcv_src = {GXcopy};
309 ; XGCValues gcv = gcv_src;
310 ; struct texture *self = malloc(sizeof(*self));
311 ; XWindowAttributes xwa;
314 ; XGetWindowAttributes(dpy, window, &xwa);
317 ; self->colormap = xwa.colormap;
319 ; self->graininess = get_integer_resource(dpy, "graininess", "Graininess");
320 ; self->lines = get_integer_resource(dpy, "speed", "Speed");
322 ; for(i = 0; i != 64; ++i)
325 ; unsigned short a = i * (0x10000 / 64);
330 ; if(!XAllocColor(dpy, xwa.colormap, &color))
332 ; self->palette[i] = color.pixel;
337 ; if(!XAllocColor(dpy, xwa.colormap, &color))
339 ; self->palette[i | 64] = color.pixel;
342 ; self->gc = XCreateGC(dpy, window, GCFunction, &gcv);
343 ; self->image = XCreateImage(dpy, xwa.visual, xwa.depth, ZPixmap, 0, NULL, 0, 1, 32, 0);
346 ; texture_reshape(dpy, window, self, xwa.width, xwa.height);
351 ;static unsigned long texture_draw(Display *dpy, Window window, void *self_raw)
353 ; struct texture *self = self_raw;
355 ; XCopyArea(dpy, window, window, self->gc, 0, self->lines, self->width, self->height - self->lines, 0, 0);
356 ; for(y = 0; y != self->lines; ++y)
357 ; _put_line(self, dpy, window, self->height - self->lines + y);
361 ;static Bool texture_event (Display *dpy, Window window, void *self_raw, XEvent *event)
366 ;static void texture_free(Display *dpy, Window window, void *self_raw)
368 ; struct texture *self = self_raw;
370 ; XFreeGC(dpy, self->gc);
371 ; XFreeColors(dpy, self->colormap, self->palette, 128, 0);
372 ; XDestroyImage(self->image);
377 ;static const char *texture_defaults[] =
386 ;static XrmOptionDescRec texture_options[] =
388 ; {"-speed", ".speed", XrmoptionSepArg, 0},
389 ; {"-graininess", ".graininess", XrmoptionSepArg, 0},
393 ;XSCREENSAVER_MODULE("Texture", texture)