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); }
/* 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; }
static int PyLibPlot_init(struct PyLibPlot* self, PyObject *args, PyObject *kwds) { int status=0; PyObject *params_dict=NULL; char *type=NULL; char *filename=NULL; plPlotterParams *params; self->fptr=NULL; if ( !PyArg_ParseTuple( args, "sOs", &type, ¶ms_dict, &filename) ) { return -1; } // for the repr snprintf(self->type, sizeof(self->type), "%s", type); params = pl_newplparams(); if (!extract_params(params_dict, params)) { // exception set inside goto bail; } if (0 != strcmp(filename, "")) { // a filename was passed self->fptr = fopen(filename,"w"); if (self->fptr==NULL) { fprintf(stderr,"error opening %s\n", filename); PyErr_Format( PyExc_TypeError, "could not open file: %s", filename); goto bail; } } self->pl = pl_newpl_r( type, NULL, self->fptr, NULL, params ); if (!self->pl) { PyErr_SetString(PyExc_RuntimeError, "could not create plotter"); goto bail; } status=1; bail: pl_deleteplparams( params ); if (!status) { return -1; } else { return 0; } }
/* user-callable */ int pl_newpl (const char *type, FILE *infile, FILE *outfile, FILE *errfile) { Plotter *new_plotter; bool open_slot; int i, j; if (_old_api_plotters_len == 0) /* initialize local array of Plotters, and install default Plotter as Plotter #0 */ _create_and_select_default_plotter (); /* create the default Plotter by invoking function in new API (make sure global PlotterParams struct, used by the old API, is set up first) */ if (_old_api_global_plotter_params == NULL) _old_api_global_plotter_params = pl_newplparams(); new_plotter = pl_newpl_r (type, infile, outfile, errfile, _old_api_global_plotter_params); /* ensure local array has an open slot (slot i) */ open_slot = false; for (i = 0; i < _old_api_plotters_len; i++) if (_old_api_plotters[i] == NULL) { open_slot = true; break; } if (!open_slot) /* expand array, clearing upper half */ { i = _old_api_plotters_len; _old_api_plotters = (Plotter **)_pl_xrealloc (_old_api_plotters, 2 * _old_api_plotters_len * sizeof (Plotter *)); for (j = _old_api_plotters_len; j < 2 * _old_api_plotters_len; j++) _old_api_plotters[j] = (Plotter *)NULL; _old_api_plotters_len *= 2; } /* place newly created Plotter in open slot */ _old_api_plotters[i] = new_plotter; /* return index of newly created Plotter */ return i; }
/* Create a new plotter whose output and error are Guile ports */ SCM gupl_newpl (SCM type, SCM outp, SCM errp, SCM param) { char *c_type; FILE *c_outp, *c_errp; plPlotter *ret; plPlotterParams *c_param; SCM_ASSERT (scm_is_string (type), type, SCM_ARG1, "newpl"); SCM_ASSERT (scm_is_true (scm_output_port_p (outp)), outp, SCM_ARG2, "newpl"); SCM_ASSERT (scm_is_true (scm_output_port_p (errp)), errp, SCM_ARG3, "newpl"); SCM_ASSERT (_scm_is_plparams (param), param, SCM_ARG4, "newpl"); /* Convert the output port to a special stream */ c_outp = fopencookie (SCM2PTR (outp), "wb", port_funcs); /* Don't buffer port here, since the underlying Guile port also has port buffering. Double buffering causes problems. */ setvbuf (c_outp, NULL, _IONBF, 0); if (c_outp == NULL) scm_syserror ("newpl"); /* Convert the err port to a special stream */ c_errp = fopencookie (SCM2PTR (errp), "wb", port_funcs); if (c_errp == NULL) scm_out_of_range ("newpl", errp); setvbuf (c_errp, NULL, _IONBF, 0); c_type = scm_to_locale_string (type); c_param = _scm_to_plparams (param); ret = pl_newpl_r (c_type, NULL, c_outp, c_errp, c_param); free (c_type); if (ret == NULL) return SCM_BOOL_F; return _scm_from_plotter (ret); }
/* Expand the local array of Plotters to include a single Plotter, of default type; also, select that Plotter. When this is invoked, the array has zero size. */ static void _create_and_select_default_plotter (void) { int i; Plotter *default_plotter; /* create the default Plotter by invoking function in new API (make sure global PlotterParams struct, used by the old API, is set up first) */ if (_old_api_global_plotter_params == NULL) _old_api_global_plotter_params = pl_newplparams(); default_plotter = pl_newpl_r (DEFAULT_PLOTTER_TYPE, stdin, stdout, stderr, _old_api_global_plotter_params); /* initialize local array of Plotters */ _old_api_plotters = (Plotter **)_pl_xmalloc (INITIAL_PLOTTERS_LEN * sizeof(Plotter *)); for (i = 0; i < INITIAL_PLOTTERS_LEN; i++) _old_api_plotters[i] = (Plotter *)NULL; _old_api_plotters_len = INITIAL_PLOTTERS_LEN; /* place default Plotter in local array, and select it */ _old_api_plotters[0] = default_plotter; _old_api_plotter = default_plotter; }