/* A simple graphics library for CSE 20211 by Douglas Thain Updated / extended by R. Ansari (Dec 2024) Paris-Saclay Univ., for Magistere C-language course project This work is licensed under a Creative Commons Attribution 4.0 International License. https://creativecommons.org/licenses/by/4.0/ For complete documentation, see: http://www.nd.edu/~dthain/courses/cse20211/fall2013/gfx Version 3, 11/07/2012 - Now much faster at changing colors rapidly. Version 2, 9/23/2011 - Fixes a bug that could result in jerky animation. ------ December 2024 Version V=4 ? 27/12/2024 - by R. Ansari , Univ. Paris-Saclay, for Magistere C-language course project */ #include #include #include #include #include #include "gfx.h" /* gfx_open creates several X11 objects, and stores them in globals for use by the other functions in the library. */ static Display *gfx_display=0; static Window gfx_window; static GC gfx_gc; static Colormap gfx_colormap; static int gfx_fast_color_mode = 0; /* R. Ansari - December 2024 , added predefined color values */ #define NPREDEFCOLS 15 XColor gfx_predef_colors[NPREDEFCOLS]; /* These values are saved by gfx_wait then retrieved later by gfx_xpos and gfx_ypos. */ static int saved_xpos = 0; static int saved_ypos = 0; /* Open a new graphics window - default background color=black */ void gfx_open( int width, int height, const char *title) { gfx_open_c(width, height, title, gfx_black); } /* Open a new graphics window with a specified background color */ void gfx_open_c( int width, int height, const char *title, enum gfx_colors bkgcol) { gfx_display = XOpenDisplay(0); if(!gfx_display) { fprintf(stderr,"gfx_open: unable to open the graphics window.\n"); exit(1); } Visual *visual = DefaultVisual(gfx_display,0); if(visual && visual->class==TrueColor) { gfx_fast_color_mode = 1; } else { gfx_fast_color_mode = 0; } unsigned long blackColor = BlackPixel(gfx_display, DefaultScreen(gfx_display)); unsigned long whiteColor = WhitePixel(gfx_display, DefaultScreen(gfx_display)); gfx_colormap = DefaultColormap(gfx_display,0); // R. Ansari - December 2024 : Allocating predefinded colors XColor exact_color; for(int i=0; i