// -------------------------------
//  The Clebsch diagonal surface:
//  a smooth cubic surface
//  admitting the symmetry
//  of the tetrahedron
// -------------------------------

//  set image size 
illumination = ambient_light+diffuse_light+transmitted_light+reflected_light;
width =400;
height=400;
set_size;
curve_red=100;
curve_green=50;
curve_blue=0;
//  define some useful constants

double  w2=sqrt(2.0); 
double  Pi=2*arccos(0);

//  define tetrahedral coordinates

poly p=1-z-w2*x;
poly q=1-z+w2*x;
poly r=1+z+w2*y;
poly s=1+z-w2*y;

//  symmetric polynomials 

poly c1=p  +q  +r  -s;
poly c2=p^3+q^3+r^3-s^3;

//  fix rotation

first  = translate;
second = rotate;
third  = scale;

rot_x=-0.5;
rot_y= 4.35;
rot_z=-0.58+Pi;

//  fix scaling

double  sf = 0.6;

scale_x=sf;
scale_y=sf*0.5;
scale_z=sf;

//  visible area and perspective

depth_cueing=yes;
depth=-20;
radius=9;
spec_z=30;
perspective=central;
antialiasing=4;

// fix light

ambient   =20;
diffuse   =60;
reflected =70;
smoothness=30;

light1_x  =-100;
light1_y  = 100;
light1_z  = 100;
light1_vol=  80;

light3_x  = 100;
light3_y  =  20;
light3_z  =  50;
light3_vol=  60;

light8_x  =-100;
light8_y  = 100;
light8_z  = 100;
light8_vol=  20;

//   surface color

//  define the diagonal surface

poly clebsch = c2 - c1^3;
surface=clebsch;

//  draw the surface

clear_screen;
cutsurface1=rotate(clebsch,1.0,xAxis);
// surface2=cutsurface1;
draw_surface;
curve_width=6;
cut_with_surface;

filename="| rasttopnm | ppmtoxpm >surf.xpm";
color_file_format=sun;
color_file_colormap=Optimized;
save_color_image;
