5 #include <X11/XCB/xcb.h>
6 #include <X11/XCB/shm.h>
7 #include <X11/XCB/xcb_aux.h>
8 #include <X11/XCB/xcb_image.h>
15 /* Parameters of the fractal */
17 /* double cr = -0.7927; */
18 /* double ci = 0.1609; */
20 /* double cr = 0.32; */
21 /* double ci = 0.043; */
23 /* double cr = -1.1380; */
24 /* double ci = -0.2403; */
26 /* double cr = -0.0986; */
27 /* double ci = -0.65186; */
29 /* double cr = -0.1225; */
30 /* double ci = 0.7449; */
34 double origin_x = -1.8;
35 double origin_y = -1.2;
39 /* Numbers of colors in the palette */
43 palette_julia (Data *datap)
45 XCBAllocColorRep *rep;
48 datap->palette = (CARD32 *)malloc (sizeof (CARD32) * cmax);
50 for (i = 0 ; i < cmax ; i++)
53 rep = XCBAllocColorReply (datap->conn,
54 XCBAllocColor (datap->conn,
59 rep = XCBAllocColorReply (datap->conn,
60 XCBAllocColor (datap->conn,
62 65535, (i-127)<<9, 0),
65 rep = XCBAllocColorReply (datap->conn,
66 XCBAllocColor (datap->conn,
68 65535, 65535, (i-255)<<10),
72 datap->palette[i] = 0;
74 datap->palette[i] = rep->pixel;
81 draw_julia (Data *datap)
87 datap->image = XCBImageGet (datap->conn, datap->draw,
89 AllPlanes, datap->format);
91 for (i = 0 ; i < datap->image->width ; i++)
92 for (j = 0 ; j < datap->image->height ; j++)
94 zr = origin_x + width * (double)i / (double)datap->image->width;
95 zi = origin_y + height * (double)j / (double)datap->image->height;
97 while ((zr*zr + zi*zi < 4.0) &&
101 zr = zr*zr - zi*zi + cr;
105 XCBImagePutPixel (datap->image,
110 XCBImagePut (datap->conn, datap->draw, datap->gc, datap->image,
111 0, 0, 0, 0, W_W, W_H);
115 main (int argc, char *argv[])
125 XCBRECTANGLE rect_coord = { 0, 0, W_W, W_H};
129 data.conn = XCBConnect (0, &screen_num);
130 screen = XCBAuxGetScreen (data.conn, screen_num);
131 data.depth = XCBAuxGetDepth (data.conn, screen);
133 win.window = screen->root;
135 data.gc = XCBGCONTEXTNew (data.conn);
136 mask = GCForeground | GCGraphicsExposures;
137 valgc[0] = screen->black_pixel;
138 valgc[1] = 0; /* no graphics exposures */
139 XCBCreateGC (data.conn, data.gc, win, mask, valgc);
141 bgcolor = XCBGCONTEXTNew (data.conn);
142 mask = GCForeground | GCGraphicsExposures;
143 valgc[0] = screen->white_pixel;
144 valgc[1] = 0; /* no graphics exposures */
145 XCBCreateGC (data.conn, bgcolor, win, mask, valgc);
147 data.draw.window = XCBWINDOWNew (data.conn);
148 mask = XCBCWBackPixel | XCBCWEventMask | XCBCWDontPropagate;
149 valwin[0] = screen->white_pixel;
150 valwin[1] = KeyReleaseMask | ButtonReleaseMask | ExposureMask;
151 valwin[2] = ButtonPressMask;
152 XCBCreateWindow (data.conn, 0,
160 XCBMapWindow (data.conn, data.draw.window);
162 rect.pixmap = XCBPIXMAPNew (data.conn);
163 XCBCreatePixmap (data.conn, data.depth,
164 rect.pixmap, data.draw,
166 XCBPolyFillRectangle(data.conn, rect, bgcolor, 1, &rect_coord);
168 XCBMapWindow (data.conn, data.draw.window);
170 data.format = ZPixmap;
172 data.cmap = XCBCOLORMAPNew (data.conn);
173 XCBCreateColormap (data.conn,
177 screen->root_visual);
179 palette_julia (&data);
181 XCBSync (data.conn, 0);
183 while ((e = XCBWaitForEvent(data.conn)))
185 switch (e->response_type)
189 XCBCopyArea(data.conn, rect, data.draw, bgcolor,
190 0, 0, 0, 0, W_W, W_H);
192 XCBSync (data.conn, 0);
196 case XCBButtonRelease:
201 XCBImageDestroy (data.image);
203 XCBDisconnect (data.conn);