|
|
1.1 root 1: /*
2: * This neat little program, another in a continuing series of eye (and
3: * screen) grabbers, will cause a disease to strike a random window on your
4: * screen.... Need I say more??
5: */
6:
7:
8: #include <stdio.h>
9: #include <X/Xlib.h>
10: #include "twiddle.h"
11: #define TRUE 1
12: #define FALSE 0
13: #include <strings.h>
14:
15: typedef struct
16: {
17: int x,y;
18: int falling;
19: } BadBit;
20:
21: BadBit disease[100000];
22:
23: int NoRotted;
24:
25: Window Victim;
26: WindowInfo Info;
27:
28: caddr_t *bitmap;
29:
30: Display *dpy;
31:
32: main(argc,argv)
33: int argc;
34: char **argv;
35: {
36:
37: Window foo, *targets;
38: int ntargets;
39: char display[256];
40: int i;
41: char *strind;
42:
43: display[0] = '\0';
44:
45: for (i=0; i < argc; i++) {
46: strind = index (argv[i], ':');
47: if(strind != NULL) {
48: strncpy(display, argv[i], sizeof(display));
49: continue;
50: }
51: }
52:
53: srandom (getpid());
54: dpy = XOpenDisplay(display);
55:
56: XQueryTree(RootWindow, &foo, &ntargets, &targets);
57:
58: do
59: {
60: Victim = targets[rnd(ntargets)];
61: XQueryWindow(Victim, &Info);
62: }
63: while (Info.mapped != IsMapped && Info.type != IsOpaque);
64:
65: printf("Info:\nWindow:%d X:%d Y:%d\n", Victim, Info.x, Info.y);
66:
67: NoRotted = 0; /* Not for long.. */
68:
69: GrabBitmap();
70: while(1)
71: {
72: /* GrabBitmap(); */
73: RotMoreBits();
74: MoveBits();
75: XFlush();
76: }
77: }
78:
79: GrabBitmap()
80: {
81: XQueryWindow(Victim, &Info);
82: bitmap = (caddr_t *)calloc( XYPixmapSize(Info.width, Info.height, dpy -> dplanes) ,1 );
83: XPixmapGetXY(Victim, 0, 0, Info.width, Info.height, bitmap);
84: }
85:
86: RotABit(x,y)
87: register int x,y;
88: {
89: register BadBit *p=disease;
90: register int i;
91:
92: for(i=NoRotted; i; i--,p++)
93: if (p->x==x && p->y==y) return;
94: disease[NoRotted].x=x;
95: disease[NoRotted].y=y;
96: disease[NoRotted].falling = FALSE;
97: ++NoRotted;
98: }
99: RotMoreBits()
100: {
101: register int i, x, y, bxsz;
102: bxsz = (Info.width+15) & ~0xf ;
103:
104: for (i=100; i; --i)
105: {
106: x=rnd(Info.width);
107: y=rnd(Info.height);
108:
109: if (!fetch (bitmap, (x + y*bxsz))) { RotABit(x,y);}
110: }
111: }
112:
113: MoveBits()
114: {
115: register int i, bxsz;
116: register BadBit *p;
117:
118: bxsz = (Info.width+15) & ~0xf;
119:
120: for (i=NoRotted, p=disease; i; --i, ++p)
121: {
122: if (p->falling)
123: {
124: if (!fetch(bitmap, p->x + (p->y*bxsz)) &&
125: fetch(bitmap, p->x + (p->y+1) * bxsz))
126: {
127: set(bitmap, p->x + p->y*bxsz);
128: SetBit(p->x, p->y);
129: (p->y)+=1;
130: reset(bitmap, p->x + p->y*bxsz);
131: ClearBit(p->x, p->y);
132: }
133: else {p->falling = FALSE; RotABit(p->x, p->y+1);}
134: }
135: else
136: {
137: if (fetch(bitmap, p->x + (p -> y+1) *bxsz))
138: p->falling = TRUE;
139: }
140: }
141: }
142: SetBit(x,y)
143: int x,y;
144: {
145: XTileSet(Victim, x, y, 1, 1, WhitePixmap);
146: }
147:
148: ClearBit(x,y)
149: int x,y;
150: {
151: XTileSet(Victim, x, y, 1, 1, BlackPixmap);
152: }
153:
154: SplatBitmap()
155: {
156: Pixmap map;
157:
158: map = XStorePixmapXY(Info.width, Info.height, bitmap);
159: XPixmapPut(Victim, 0, 0, 0, 0,
160: Info.width, Info.height,
161: map, GXcopy, dpy -> dplanes);
162: XFlush();
163: XFreePixmap(map);
164: }
165:
166: rnd(n)
167: int n;
168:
169: {
170: long random();
171:
172: return (random() % n);
173: }
174:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.