[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Color plots



The eepic documentation mentions that it can fill in polygons, etc.
So I played with ePiX, and made modified versions of the ePiX plot
function that will fill in the region under the graph or between
graphs.  I thought I'd put in on the list, in case anyone wants it (or
wants to improve it).

Jay

/* Colored plotting

   blackplot(f, a, b, n) will draw the graph y=f(x) from x=a to x=b, 
      while filling the region under the graph in black.

   blackplot(f, g, a, b, n) will fill the region between the graphs 
      y=f(x) and y=g(x) from x=a to x=b in black.

   whiteplot(f, a, b, n) will draw the graph y=f(x) from x=a to x=b, 
      while filling the region under the graph in white.

   whiteplot(f, g, a, b, n) will fill the region between the graphs 
      y=f(x) and y=g(x) from x=a to x=b in white.

   shadeplot(f, a, b, n) will draw the graph y=f(x) from x=a to x=b, 
      while filling the region under the graph in grey.  

   shadeplot(f, g, a, b, n) will fill the region between the graphs 
      y=f(x) and y=g(x) from x=a to x=b in grey.

   changeshade(x) will change the shade of grey used in shadeplot,
      changeshade(0) will make it fairly white, and changeshade(1) 
      will make it pretty black.  (Okay, this doesn't work very well,
      there are only two intermediate shades right now.
      I don't know how the \texture command in eepic works.)
*/

void draw_blackplot(double f(double), double, double, int);
void draw_blackplot(double f1(double), double f2(double), double, double, int);
void blackplot(double f(double), double, double, int);
void blackplot(double f1(double), double f2(double), double, double, int);

void draw_whiteplot(double f(double), double, double, int);
void draw_whiteplot(double f1(double), double f2(double), double, double, int);
void whiteplot(double f(double), double, double, int);
void whiteplot(double f1(double), double f2(double), double, double, int);

void draw_shadeplot(double f(double), double, double, int);
void draw_shadeplot(double f1(double), double f2(double), double, double, int);
void shadeplot(double f(double), double, double, int);
void shadeplot(double f1(double), double f2(double), double, double, int);


/* This is in epix, but needs to be defined in this file to be
   available to the functions in this file */
pair 
plot_pt(double f1(double), double f2(double), double t)
{
  return pair(f1(t), f2(t));
}


double zero (double x){
  return 0;
}

void
draw_blackplot(double f(double), double t_min, double t_max, int num_pts)
{
  double t;
  const double dt = (t_max - t_min)/num_pts;

  printf("\n\\blacken\\path"); //start_path();
  for (int i=0; i <= num_pts; ++i)
    {
      t = t_min + i*dt;
      print(plot_pt(id, f, t));

      line_break(i, num_pts);
    }
  print(plot_pt(id, zero, t_max));
  print(plot_pt(id, zero, t_min));
  print(plot_pt(id, f, t_min));
}

void
draw_blackplot(double f(double), double g(double), double t_min, double t_max, int num_pts)
{
  double t;
  const double dt = (t_max - t_min)/num_pts;

  printf("\n\\blacken\\path"); //start_path();
  for (int i=0; i <= num_pts; ++i)
    {
      t = t_min + i*dt;
      print(plot_pt(id, f, t));

      line_break(i, num_pts);
    }
  print(plot_pt(id, g, t_max));
  for (int i=0; i <= num_pts; ++i)
    {
      t = t_max - i*dt;
      print(plot_pt(id, g, t));
      line_break(i, num_pts);
    }
  print(plot_pt(id, f, t_min));
}

void
blackplot(double f(double), double t_min, double t_max, int num_pts)
{
  epix_comment("black graph plot");
  draw_blackplot(f, t_min, t_max, num_pts);
  end_stanza();
}

void
blackplot(double f(double), double g(double), double t_min, double t_max, int num_pts)
{
  epix_comment("black graph plot");
  draw_blackplot(f, g, t_min, t_max, num_pts);
  end_stanza();
}

void
draw_whiteplot(double f(double), double t_min, double t_max, int num_pts)
{
  double t;
  const double dt = (t_max - t_min)/num_pts;

  printf("\n\\whiten\\path"); //start_path();
  for (int i=0; i <= num_pts; ++i)
    {
      t = t_min + i*dt;
      print(plot_pt(id, f, t));

      line_break(i, num_pts);
    }
  print(plot_pt(id, zero, t_max));
  print(plot_pt(id, zero, t_min));
  print(plot_pt(id, f, t_min));
}

void
draw_whiteplot(double f(double), double g(double), double t_min, double t_max, int num_pts)
{
  double t;
  const double dt = (t_max - t_min)/num_pts;

  printf("\n\\whiten\\path"); //start_path();
  for (int i=0; i <= num_pts; ++i)
    {
      t = t_min + i*dt;
      print(plot_pt(id, f, t));

      line_break(i, num_pts);
    }
  print(plot_pt(id, g, t_max));
  for (int i=0; i <= num_pts; ++i)
    {
      t = t_max - i*dt;
      print(plot_pt(id, g, t));
      line_break(i, num_pts);
    }
  print(plot_pt(id, f, t_min));
}

void
whiteplot(double f(double), double t_min, double t_max, int num_pts)
{
  epix_comment("white graph plot");
  draw_whiteplot(f, t_min, t_max, num_pts);
  end_stanza();
}

void
whiteplot(double f(double), double g(double), double t_min, double t_max, int num_pts)
{
  epix_comment("white graph plot");
  draw_whiteplot(f, g, t_min, t_max, num_pts);
  end_stanza();
}

void
draw_shadeplot(double f(double), double t_min, double t_max, int num_pts)
{
  double t;
  const double dt = (t_max - t_min)/num_pts;

  printf("\n\\shade\\path"); //start_path();
  for (int i=0; i <= num_pts; ++i)
    {
      t = t_min + i*dt;
      print(plot_pt(id, f, t));

      line_break(i, num_pts);
    }
  print(plot_pt(id, zero, t_max));
  print(plot_pt(id, zero, t_min));
  print(plot_pt(id, f, t_min));
}

void
draw_shadeplot(double f(double), double g(double), double t_min, double t_max, int num_pts)
{
  double t;
  const double dt = (t_max - t_min)/num_pts;

  printf("\n\\shade\\path"); //start_path();
  for (int i=0; i <= num_pts; ++i)
    {
      t = t_min + i*dt;
      print(plot_pt(id, f, t));

      line_break(i, num_pts);
    }
  print(plot_pt(id, g, t_max));
  for (int i=0; i <= num_pts; ++i)
    {
      t = t_max - i*dt;
      print(plot_pt(id, g, t));
      line_break(i, num_pts);
    }
  print(plot_pt(id, f, t_min));
}

void
shadeplot(double f(double), double t_min, double t_max, int num_pts)
{
  epix_comment("shaded graph plot");
  draw_shadeplot(f, t_min, t_max, num_pts);
  end_stanza();
}

void
shadeplot(double f(double), double g(double), double t_min, double t_max, int num_pts)
{
  epix_comment("shaded graph plot");
  draw_shadeplot(f, g, t_min, t_max, num_pts);
  end_stanza();
}


/* Changing the shading */

void changeshade (double x){
  char* clr;
  int n;
  if (x > 1) x=1;
  if (x < 0) x=0;
  n = floor(4*x);
  switch (n) {
  case 0:
    clr="00000000";
    break;
  case 1:
    clr="11111111";
    break;
  case 2:
    clr="33333333";
    break;
  case 3:
  default:
    clr="77777777";
    break;
  }
  epix_comment("changing texture");
  printf("\n\\texture{\n");
  for (int i=0; i<32; i++){
    printf(clr);
    printf("\n");
  }
  printf("}\n");
}