/* set up the plotter and the params */ plPlotter* setUp() { plPlotter* plotter; plPlotterParams* plotterParams; /* create a plotter parametric structure */ plotterParams = pl_newplparams(); pl_setplparam(plotterParams, "BITMAPSIZE", "750x750"); pl_setplparam(plotterParams, "USE_DOUBLE_BUFFERING", "no"); pl_setplparam(plotterParams, "BG_COLOR", "black"); /* create the plotter device and open it */ if((plotter = pl_newpl_r("X", stdin, stdout, stderr, plotterParams)) == NULL) { fprintf(stderr, "Couldn't create Xwindows plotter\n"); exit(1); } else if(pl_openpl_r(plotter) < 0) { fprintf(stderr, "Couldn't open Xwindows plotter\n"); exit(1); } /* set our coordinate space in the plotter window */ double winSize = windowSize(PLANETS); pl_fspace_r(plotter, -winSize, -winSize, winSize, winSize); /* pick a type for the pen and the fill */ pl_pentype_r(plotter, 1); pl_filltype_r(plotter, 1); return plotter; }
void drawGIF( char* outputName, char* ieq, double xmin, double xmax, double ymin, double ymax, char* pass, char* fail ) { int i, j; //Open the output file FILE* outFile = fopen(outputName, "w"); if (outFile==NULL) { fprintf(stderr, "ERR: failed to open file.\n"); exit(1); } //Initialize the plotter plPlotterParams *pParams = pl_newplparams(); pl_setplparam(pParams, "BITMAPSIZE", "500x500"); plPlotter* p = pl_newpl_r("gif", stdin, outFile, stderr, pParams); //Set the plotter pl_openpl_r(p); pl_fspace_r(p, 0, 0, 500, 500); //Get the array values char*** colorArr = createImgArr(ieq, 500, 500, xmin, xmax, ymin, ymax, pass, fail); //Set the pixels for (i = 0; i < 500; i++){ for (j = 0; j < 500; j++){ pl_pencolorname_r(p, colorArr[i][j]); pl_fpoint_r(p,i,j); } } //cleanup freeImgArr(colorArr, 500); pl_endsubpath_r(p); pl_closepl_r(p); pl_deletepl_r(p); fclose(outFile); }
/* Deal with all the python3 vs python2 string issues PyBytes has been backported to newer python2 as a fake alias, but doesn't exist for older versions. */ static int set_param_from_key_value(plPlotterParams *params, PyObject *key, PyObject *value) { int status=0; char *skey=NULL, *svalue=NULL; #if PY_MAJOR_VERSION >= 3 PyObject *tmp1, *tmp2; tmp1 = PyObject_CallMethod(key,"encode",NULL); if (!tmp1) { goto bail; } skey = PyBytes_AsString(tmp1); tmp2 = PyObject_CallMethod(value,"encode",NULL); if (!tmp2) { goto bail; } svalue = PyBytes_AsString(tmp2); #else skey = PyString_AsString( key ); if (!skey) { goto bail; } svalue = PyString_AsString( value ); if (!svalue) { goto bail; } #endif pl_setplparam( params, skey, svalue ); #if PY_MAJOR_VERSION >= 3 Py_XDECREF(tmp1); Py_XDECREF(tmp2); #endif status=1; bail: return status; }
SCM gupl_setplparam_x (SCM s_plparams, SCM s_parameter, SCM s_value) { plPlotterParams *c_plparams; char *c_parameter; char *c_string_value; int c_ret; SCM_ASSERT (_scm_is_plparams (s_plparams), s_plparams, SCM_ARG1, "setplparam!"); SCM_ASSERT (scm_is_string (s_parameter), s_parameter, SCM_ARG2, "setplparam!"); SCM_ASSERT (scm_is_string (s_value), s_value, SCM_ARG3, "setplparam!"); c_plparams = _scm_to_plparams (s_plparams); c_parameter = scm_to_locale_string (s_parameter); c_string_value = scm_to_locale_string (s_value); c_ret = pl_setplparam (c_plparams, c_parameter, c_string_value); free (c_parameter); free (c_string_value); return (scm_from_int (c_ret)); }