summaryrefslogtreecommitdiff
path: root/graphics/epix/samples/levelset2.xp
blob: ab1a6050694ac0acadddd15fa884e0fa63174c6a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/* -*-ePiX-*- */
#include "epix.h"
using namespace ePiX;

// Style parameters
const int MAX(1); // maximum coordinate

domain R(P(-MAX,-MAX), P(MAX, MAX), (24, 24), mesh(72,72));

const double sqrt3(sqrt(3));

// function to be graphed
P f(double x, double y)
{
  return P(x, y, 0.75*y*(y-sqrt3*x)*(y+sqrt3*x));
}

P color(double u, double v, double w)
{
  return P(-0.5*w, 0.25*w, 0.95*w);
}

int main()
{
  picture(P(-2*MAX,-2*MAX), P(2*MAX,2*MAX), "6 x 6in");

  begin();

  border(Green(0.6), "1pt");
  backing(Black());

  camera.at(sph(4*MAX, M_PI/6, M_PI/6));

  // positioned for viewpt in first orthant
  yellow();
  grid(P(-MAX,-MAX,-MAX), P(MAX,MAX,-MAX), 4, 4);
  grid(P(-MAX,-MAX,-MAX), P(MAX,-MAX,MAX), 4, 4);
  grid(P(-MAX,-MAX,-MAX), P(-MAX,MAX,MAX), 4, 4);

  axis Ax(P(-MAX,-MAX,MAX), P(MAX,-MAX,MAX), 4, P(0,6), t);
  axis Ay(P(MAX,-MAX,-MAX), P(MAX,MAX,-MAX), 4, P(-2,-2), bl);
  axis Az(P(MAX,-MAX,-MAX), P(MAX,-MAX,MAX), 4, P(-2,-2), bl);

  Ax.frac().draw();
  Ay.frac().draw();
  Az.frac().draw();

  clip_box(P(MAX,MAX,MAX));

  // wire mesh surface
  plain(Green());
  plot(f, R);

  // level bands
  plain(Red());

  for (int i=-5; i <=5; ++i)
    {
      clip_slice(P(0,0,0.2*i), P(0,0,1), 0.1);
#ifdef FLATFILL
      fill(RGB(0.25+0.1*i, 0, -0.1*i)); // index-dependent coloring
      surface(f, R);
#else
      surface(f, R, color); // domain- or position-dependent coloring
#endif
      clip_restore(); // remove temporary slicing planes, keep clip box
    }

  pst_format();
  end();
}