/******************************************* * Copyright (C) 1990 by Christopher R. Wren and * the Massachusetts Institute of Technology * * COMMERCIAL DISCLAIMER: * * This software is intended for research purposes only and contains * unlicensed software, in original and modified forms, from various * sources including the Free Software Foundation. These programs * shall not be used, rewritten, or adapted as the basis of a * commercial software or hardware product without first obtaining * appropriate licenses from the owners of the original software * copyrights. * * In the case of copyrighted software fragments obtained from the * Free Software Foundation: you can redistribute it and/or modify it * under the terms of the GNU Library General Public License as * published by the Free Software Foundation. This software is * distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General * Public License for more details. You should have received a copy * of the GNU Library General Public License and the GNU General * Public License along with this software; if not, write to the Free * Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. * * Developed by Christopher R. Wren at the * Media Laboratory, MIT, Cambridge, Massachusetts. * *******************************************/ #include XtAppContext context; int color[256]; Widget simple; GC gc; Window win; Display *dpy; static String *fallback_resources = { NULL, }; /* Function Name: ConvertColor * Description: This converts a string into a color. * Arguments: color_name - name of the color. * Returns: a pixel value for that color. */ static int ConvertColor(w, color_name) Widget w; char * color_name; { XrmValue from, to; from.size = strlen(color_name) + 1; from.addr = color_name; /* * This conversion accepts a colorname from rgb.txt, or a #rrrgggbbb * rgb color definition, or the special toolkit strings "XtDefaultForeground" * and "XtDefaultBackground". */ XtConvert(w, XtRString, (XrmValuePtr) &from, XtRPixel, (XrmValuePtr) &to); if (to.addr == NULL) { return(-1); } return( (int) *((Pixel *) to.addr) ); } void init_display(argc,argv,x,y) int x; int y; int *argc; String *argv; { Arg args[10]; int nargs = 0; nargs = 0; XtSetArg(args[nargs],XtNwidth,x); nargs++; XtSetArg(args[nargs],XtNheight,y); nargs++; { Widget toplevel = XtAppInitialize(&context, "Fractals", NULL, 0, argc, argv, fallback_resources, args,nargs); XtRealizeWidget(toplevel); dpy = XtDisplay(toplevel); { Colormap old; nargs = 0; XtSetArg(args[nargs],XtNcolormap,&old); nargs++; XtGetValues(toplevel,args,nargs); { Colormap new = XCopyColormapAndFree(dpy,old); { char cname[100]; int i; for (i=0; i<256 ; i++) { int r = abs(((i + 120) % 256) - 127); int g = abs(((i + 160) % 256) - 127); int b = abs(((i + 200) % 256) - 127); sprintf(cname,"#%02x%02x%02x",r,g,b); if ((color[i] = ConvertColor(toplevel,cname)) < 0) fprintf(stderr,"FAILED to alloc %s\n",cname); } } nargs = 0; XtSetArg(args[nargs],XtNwidth,x); nargs++; XtSetArg(args[nargs],XtNheight,y); nargs++; XtSetArg(args[nargs],XtNcolormap,new); nargs++; simple = XtCreateManagedWidget("canvas", simpleWidgetClass, toplevel, args, nargs); win = XtWindow(simple); { XGCValues gcv; unsigned long gcm =0; gc = XtGetGC(simple,gcm,&gcv); } } } } } void destroy_display() { fprintf(stderr,"done\n"); XtAppMainLoop(context); } void draw_pixel(c,x,y,s) int c,x,y,s; { XSetForeground(dpy,gc,color[c%256]); XFillRectangle(dpy,win,gc,x,y,s,s); } void do_event() { while(XtAppPending(context)) { XEvent event; XtAppNextEvent(context,&event); XtDispatchEvent(&event); } }