surface olympicsurf( float radius = 0.160, /* outer radius */ thick = 0.050 /* dist to inner radius */ ) { float r; /* radius to center of ring */ vector Nf; /* norward-facing surface normal */ vector V; /* vector toward eye */ color C; /* new color */ color O; /* new opacity */ /* transparency possibilities: */ color clear = color ( 0., 0., 0. ); color opaque = color ( 1., 1., 1. ); /* colors of the circles: */ color blue = color "rgb" ( 0,0,1 ); color yellow = color "rgb" ( 1,1,0 ); color black = color "rgb" ( 0,0,0 ); color green = color "rgb" ( 0,1,0 ); color red = color "rgb" ( 1,0,0 ); color white = color "rgb" ( 1,1,1 ); /* centers of the circles in (s,t) space: */ point pblue = point ( 0.250, 0.600, 0.0 ); point pyellow = point ( 0.375, 0.400, 0.0 ); point pblack = point ( 0.500, 0.600, 0.0 ); point pgreen = point ( 0.625, 0.400, 0.0 ); point pred = point ( 0.750, 0.600, 0.0 ); /* where we are right now in (s,t) space: */ point here = point ( s, t, 0.0 ); /* default: color & opacity are whatever was given by the program: */ C = Cs; O = Os; /* are we within the blue ring? */ r = distance( here, pblue ); if( (radius-thick) <= r && r <= radius ) { C = blue; O = opaque; } /* are we within the yellow ring? */ r = distance( here, pyellow ); if( (radius-thick) <= r && r <= radius ) { C = yellow; O = opaque; } /* are we within the black ring? */ r = distance( here, pblack ); if( (radius-thick) <= r && r <= radius ) { C = black; O = opaque; } /* are we within the green ring? */ r = distance( here, pgreen ); if( (radius-thick) <= r && r <= radius ) { C = green; O = opaque; } /* are we within the red ring? */ r = distance( here, pred ); if( (radius-thick) <= r && r <= radius ) { C = red; O = opaque; } /* determine a couple of useful vectors: */ Nf = faceforward( normalize(N), I ); V = -normalize(I); /* assign the incident (eye) opacity and color: */ Oi = O; Ci = O * ( C * ( ambient() + diffuse(Nf) ) + specular(Nf,V,0.1) ); }