* Shader description goes here */
  
#include "lcl_funlib.h"
  
surface
panda (float    verticleFlip = 1, /* [0 or 1] */
                horizontalFlip = 1, /* [0 or 1] */
                Ka =0.8 ,
                 Kd =0.8 ,
                Ks =0.5,
                roughness =0.1,
                rear =0.02,
                Reye =0.001, /* eye size  */ 
                eyeP =0.2,
                 eyeP2 =0.2,
             
                mouth =0.1;
            
                 color     surfcircle1 = color (0.2,0.2,0.2),
                        face = color (1,0,0),
                        cheek = color (1.0,0.8,0.8),
                        
                        hilitecolor = 1 )
{
Oi = 1;
color surfcolor = Oi ;
normal n = normalize (N);
  
vector i = normalize (I);
  
  
float tt = 1-t;
if (verticleFlip == 0)
    tt=t;
float ss = 1-s;
if (horizontalFlip == 0)
    ss = s;
    
  
/*stripe
if (tt >=0.5 && tt <=0.6)
    surfcolor= color (0.0,0.0,0.0); 
stripe*/
  
  
  
  
  
  
/*Ears....................................................*/
float circle1;
float earback;
  
earback = (pow( ss -.195, 2) + pow(tt -.195, 2));
 if( earback <= rear)
    surfcolor = color ( 0.8,0.8,0.8);
circle1 = (pow( ss -.2, 2) + pow(tt -.2, 2));
 if( circle1 <= rear)
    surfcolor = surfcircle1;
  
float circle2;
float earback2;
  
earback2 = (pow( ss -.805, 2) + pow(tt -.195, 2));
 if( earback2 <= rear)
    surfcolor = color ( 0.8,0.8,0.8);    
  
circle2 = (pow( ss -.8, 2) + pow(tt -.2, 2));
 if (circle2 <= rear)
    surfcolor = surfcircle1;
  
/*Ears....................................................*/    
/*face....................................................*/    
  
  
float backcircle; 
backcircle = (pow( ss -.5, 2) + pow(tt -.5, 2));
if (backcircle <= .189)
    surfcolor = color ( 0.8,0.8,0.8);
  
  
float circle3;
circle3 = (pow( ss -.5, 2) + pow(tt -.5, 2));
 if (circle3 <= .18)
    surfcolor = face;
    
        
/*face....................................................*/
/*eyes....................................................*/
  
float eyes1;
float eyes2;
  
eyes1= (pow( ss -.3, 2) + pow(tt - eyeP, 2));
eyes2= (pow( ss -.7, 2) + pow(tt - eyeP2, 2));
  
if( eyes2 <= Reye)
    surfcolor= color (0.2,0.2,0.2);
if( eyes1 <= Reye)
    surfcolor= color (0.2,0.2,0.2);
/*eyes....................................................*/
  
/*the mouth------------------------------------------------*/
  
  
float circle4;
float circle5;
  
circle4 = sqrt( (ss -.5) * (ss -.5) + (tt -.7) * (tt -.7) );
circle5 = sqrt( (ss -.5) * (ss -.5) + (tt -.71) * (tt -.71) );
  
if ( circle5 < mouth && circle4 > mouth )
    surfcolor= color (0.2,0.2,0.2);
  
/*the mouth-----------------------------------------------*/
  
/*cheeks---------------------------------------------------*/
  
if (sqrt( (ss -.23) * (ss -.23) + (tt -.6) * (tt -.6) ) <=.095)
    surfcolor= cheek;
if (sqrt( (ss -.77) * (ss -.77) + (tt -.6) * (tt -.6) ) <=.095)
    surfcolor= cheek;
  
/*cheeks--------------------------------------------------*/
  
/*the nose */    
if( ss >= 0.45 && ss <= 0.5 && tt >= 0.5 && tt <= 0.55 )
    surfcolor = color (0.2,0.2,0.2) ;
if( ss >= 0.5 && ss <= 0.55 && tt >= 0.5 && tt <= 0.55 )
    surfcolor = color (0.2,0.2,0.2) ;    
if( ss >= 0.48 && ss <= 0.5 && tt >= 0.55 && tt <= 0.6 )
    surfcolor = color (0.2,0.2,0.2) ;
if( ss >= 0.5 && ss <= 0.52 && tt >= 0.55 && tt <= 0.6 )
    surfcolor = color (0.2,0.2,0.2) ;
/*the nose */
  
color ambientColor = ambient() * Ka;
color diffuseColor = diffuse(n) * Kd;
color specColor = specular (n, -i, roughness) * hilitecolor * Ks;
  
color white = 1;
  
/* to make surface transparent */
  
if(surfcolor == white)
    Oi = 0;
else
    Oi = Os;
  
  
  
/* STEP 2 - calculate the apparent surface color */
Ci = Oi * Cs * surfcolor * (ambientColor + diffuseColor + specColor);
}