Пример #1
0
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);
    
}
Пример #2
0
/* 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;

}
Пример #3
0
SCM
gupl_newplparams (void)
{
  plPlotterParams *c_plparams;
  c_plparams = pl_newplparams ();
  return _scm_from_plparams (c_plparams);
}
Пример #4
0
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, &params_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;
    }

}
Пример #5
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;
}
Пример #6
0
/* 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;
}