#local ov = version;
#version 3.7;

#declare Tex_Wood =
texture {
  pigment {
    wood
    color_map {
      [0.6 rgb <0.88, 0.60, 0.30>]
      [0.8 rgb <0.60, 0.40, 0.20>]
      [1.0 rgb <0.60, 0.50, 0.30>]
    }
    warp {
      turbulence 0.3
      lambda 3
      omega 0.7
    }
    scale 0.05
    rotate <90,0,0>
  }
  normal {
    granite 0.1
    scale 0.05
  }
  finish {
    ambient 0.1
    diffuse 0.7
    brilliance 3
    specular 0.8
    roughness 0.01
  }
}

//Pirate
#macro Pirate(mvs_l, mvs_r)
  
  #local roa_l = mvs_l[0];
  #local rua_l = mvs_l[1];
  #local roa_r = mvs_r[0];
  #local rua_r = mvs_r[1];
  
  #local Tex_Skin =
  texture {
    pigment { rgb <0.9,0.8,0.3> }
    normal {
      wrinkles 0.5
      scale 0.005
    }
    finish {
      ambient 0.2
      diffuse 0.6
      brilliance 0
      specular 0.5
      roughness 0.01
    }
  }
  
  #local Hand =
  blob {
    /* Copied from the Blob Object Tutorial */
    threshold .65
    sphere{<-.23,-.32,0>,.43, 1 scale <1.95,1.05,.8>}   //palm
    sphere{<+.12,-.41,0>,.43, 1 scale <1.95,1.075,.8>}  //palm
    sphere{<-.23,-.63,0>, .45, .75 scale <1.78, 1.3,1>} //midhand
    sphere{<+.19,-.63,0>, .45, .75 scale <1.78, 1.3,1>} //midhand
    sphere{<-.22,-.73,0>, .45, .85 scale <1.4, 1.25,1>} //heel
    sphere{<+.19,-.73,0>, .45, .85 scale <1.4, 1.25,1>} //heel
    cylinder{<-.65,-.28,0>, <-.65,.28,-.05>, .26, 1}    //lower pinky
    cylinder{<-.65,.28,-.05>, <-.65, .68,-.2>, .26, 1}  //upper pinky
    cylinder{<-.3,-.28,0>, <-.3,.44,-.05>, .26, 1}      //lower ring
    cylinder{<-.3,.44,-.05>, <-.3, .9,-.2>, .26, 1}     //upper ring
    cylinder{<.05,-.28,0>, <.05, .49,-.05>, .26, 1}     //lower middle
    cylinder{<.05,.49,-.05>, <.05, .95,-.2>, .26, 1}    //upper middle
    cylinder{<.4,-.4,0>, <.4, .512, -.05>, .26, 1}      //lower index
    cylinder{<.4,.512,-.05>, <.4, .85, -.2>, .26, 1}    //upper index
    cylinder{<.41, -.95,0>, <.85, -.68, -.05>, .25, 1}  //lower thumb
    cylinder{<.85,-.68,-.05>, <1.2, -.4, -.2>, .25, 1}  //upper thumb
    sphere{<-.65,.28,-.05>, .26, -1} //counteract pinky knucklebulge
    sphere{<-.65,-.28,0>, .26, -1}   //counteract pinky palm bulge
    sphere{<-.3,.44,-.05>, .26, -1}  //counteract ring knuckle bulge
    sphere{<-.3,-.28,0>, .26, -1}    //counteract ring palm bulge
    sphere{<.05,.49,-.05>, .26, -1}  //counteract middle knuckle bulge
    sphere{<.05,-.28,0>, .26, -1}    //counteract middle palm bulge
    sphere{<.4,.512,-.05>, .26, -1}  //counteract index knuckle bulge
    sphere{<.4,-.4,0>, .26, -1}      //counteract index palm bulge
    sphere{<.85,-.68,-.05>, .25, -1} //counteract thumb knuckle bulge
    sphere{<.41,-.7,0>, .25, -.89}   //counteract thumb heel bulge
    scale 0.07
    rotate <180,0,0>
  }
  
  union {
    
    //(torn) trousers
    difference {
      
      //(intact) trousers
      difference {
        
        #local s10 = sin(pi/18);
        #local c10 = cos(pi/18);
        
        union {
          
          ovus {
            0.2, 0.1
            rotate <90,0,0>
            scale <1,0.5,0.2/0.5>
            translate <0,0,0.1>
          }
          
          cylinder {
            <0,-0.3,0.075>, <0,0,0.075>, 0.05
            rotate <0,0,10>
            translate <0.1,0,0.01>
          }
          
          cylinder {
            <0,-0.3,0.075>, <0,0,0.075>, 0.05
            rotate <0,0,-10>
            translate <-0.1,0,0.01>
          }
          
          cylinder {
            <-0.3*s10-0.1,-0.6,0.09>, <-0.3*s10-0.1,-0.3*c10,0.085>, 0.05
          }
          
          sphere {
            <-0.3*s10-0.1,-0.3*c10,0.085>, 0.05
          }
          
        }
        
        union {
          
          cylinder {
            <0,-0.4,0.075>, <0,0,0.075>, 0.04
            rotate <0,0,10>
            translate <0.1,0,0.01>
          }
          
          cylinder {
            <0,-0.3,0.075>, <0,0,0.075>, 0.04
            rotate <0,0,-10>
            translate <-0.1,0,0.01>
          }
          
          cylinder {
            <-0.3*s10-0.1,-0.7,0.09>, <-0.3*s10-0.1,-0.3*c10,0.085>, 0.04
          }
          
          sphere {
            <-0.3*s10-0.1,-0.3*c10,0.085>, 0.04
          }
          
        }
        
      }
      
      #local f_rags = function { pattern { granite scale 0.1 } }
      
      isosurface {
        function { f_rags(x,y/5,z)-0.7+7*(5*y+3)/25 }
        contained_by { box { <-0.3*s10-0.16,-0.65,0.03>, <0.3*s10+0.16,-0.1,0.14> } }
      }
      
      texture {
        pigment { rgb <0,0,1> }
        normal {
          granite
          scale 0.01
        }
        finish {
          ambient 0.1
          diffuse 0.5
          brilliance 0.5
          specular 0
        }
      }
      
    }
    
    //leg
    union {
      
      cone {
        <0,-0.3,0.075>, 0.03, <0,0,0.075>, 0.04
        rotate <0,0,10>
        translate <0.1,0,0.01>
      }
      
      cone {
        <0,-0.3,0.075>, 0.03, <0,0,0.075>, 0.04
        rotate <0,0,-10>
        translate <-0.1,0,0.01>
      }
      
      cylinder {
        <-0.3*s10-0.1,-0.6,0.09>, <-0.3*s10-0.1,-0.3*c10,0.085>, 0.03
      }
      
      sphere {
        <-0.3*s10-0.1,-0.3*c10,0.085>, 0.03
      }
      
      sphere {
        <0.3*s10+0.1,-0.3*c10,0.085>, 0.03
      }
      
      texture { Tex_Skin }
      
    }
    
    //foot
    union {
      
      torus {
        0.04, 0.01
        sturm
      }
      
      intersection {
        
        sphere {
          <0,0,0>, 1
          scale <0.06,0.05,0.1>
          translate <0,-0.05*cos(pi/10),-0.1*sin(pi/10)>
        }
        
        plane {
          -y, 0.05
        }
        
      }
      
      cylinder {
        <0,-0.01,0>, <0,0,0>, 1
        scale <0.07,1,0.11>
        translate <0,-0.05*cos(pi/10),-0.1*sin(pi/10)>
      }
      
      texture {
        pigment { rgb <1,0,0> }
        normal {
          bozo 2
          noise_generator 3
          scale 0.001
        }
        finish {
          ambient 0.1
          diffuse 0.6
          brilliance 0.2
          specular 0
        }
      }
      
      translate <-0.3*s10-0.1,-0.6,0.09>
      
    }
    
    //peg leg
    cylinder {
      <0,-0.61-0.05*cos(pi/10)+0.3*c10,0>, <0,0,0>, 0.01
      translate <0.3*s10+0.1,-0.3*c10,0.085>
      
      texture { Tex_Wood }
    }
    
    //shirt
    union {
      
      cone {
        <0,0.05,0>, 0.1, <0,0.3,0>, 0.07
      }
      
      sphere {
        <0,0.3,0>, 0.07
      }
      
      difference {
        
        union {
          
          union {
            
            cylinder {
              <0,0.15,0>, <0,0.3,0>, 0.03
            }
            
            sphere {
              <0,0.15,0>, 0.03
            }
              
            cylinder {
              <0,-0.1,0>, <0,0.15,0>, 0.03
              
              translate <0,-0.15,0>
              rotate rua_l
              translate <0,0.15,0>
            }
            
            translate <0,-0.3,0>
            rotate roa_l
            translate <0.04,0.3,0>
            
          }
          
          union {
            
            cylinder {
              <0,0.15,0>, <0,0.3,0>, 0.03
            }
            
            sphere {
              <0,0.15,0>, 0.03
            }
              
            cylinder {
              <0,-0.1,0>, <0,0.15,0>, 0.03
              
              translate <0,-0.15,0>
              rotate rua_r
              translate <0,0.15,0>
            }
            
            translate <0,-0.3,0>
            rotate roa_r
            translate <-0.04,0.3,0>
            
          }
          
        }
        
        union {
          
          union {
            
            cylinder {
              <0,0.15,0>, <0,0.3,0>, 0.02
            }
            
            sphere {
              <0,0.15,0>, 0.02
            }
            
            cylinder {
              <0,-0.2,0>, <0,0.15,0>, 0.02
              
              translate <0,-0.15,0>
              rotate rua_l
              translate <0,0.15,0>
            }
            
            translate <0,-0.3,0>
            rotate roa_l
            translate <0.04,0.3,0>
            
          }
          
          union {
            
            cylinder {
              <0,0.15,0>, <0,0.3,0>, 0.02
            }
            
            sphere {
              <0,0.15,0>, 0.02
            }
            
            cylinder {
              <0,-0.2,0>, <0,0.15,0>, 0.02
              
              translate <0,-0.15,0>
              rotate rua_r
              translate <0,0.15,0>
            }
            
            translate <0,-0.3,0>
            rotate roa_r
            translate <-0.04,0.3,0>
            
          }
          
        }
        
      }
      
      texture {
        pigment { rgb <1,1,0> }
        normal {
          wrinkles 0.1
          scale 0.01
        }
        finish {
          ambient 0.1
          diffuse 0.5
          brilliance 0.5
          specular 0
        }
      }
      
      scale <1.5,1,0.8>
      translate <0,0,0.1>
      
    }
    
    //normal hand
    union {
      
      cone {
        <0,-0.15,0>, 0.015, <0,0.15,0>, 0.02
      }
      
      object {
        Hand
        matrix
        <-1,0,0,
         0,1,0,
         0,0,1,
         0,0,0>
        translate <0,-0.2,0>
      }
      
      texture { Tex_Skin }
              
      translate <0,-0.15,0>
      rotate rua_l
      translate <0,-0.15,0>
      rotate roa_l
      translate <0.04*3,0.3,0.1>
      
    }
    
    //prosthetic hook
    union {
      
      cone {
        <0,-0.15,0>, 0.015, <0,0.15,0>, 0.02
      }
      
      union {
        
        sphere {
          <0,-0.15,0>, 0.015
        }
        
        sphere_sweep {
          b_spline 7,
          <0,-0.15,0>, 0.005
          <0,-0.165,0>, 0.005
          <0,-0.205,0>, 0.005
          <-0.04,-0.205,0>, 0.005
          <-0.04,-0.285,0>, 0.005
          <0.04,-0.285,0>, 0
          <0.04,-0.2,0>, 0
        }
        
        texture {
          pigment { rgb 1 }
          normal {
            bozo
            scale 0.001
          }
          finish {
            ambient 0.1
            diffuse 0.6
            brilliance 1
            specular 0.9
            roughness 0.005
            metallic 0.5
            reflection {
              0, 0.5
              metallic 0.5
            }
            conserve_energy
          }
        }
        
      }
      
      texture { Tex_Skin }
              
      translate <0,-0.15,0>
      rotate rua_r
      translate <0,-0.15,0>
      rotate roa_r
      translate <-0.04*3,0.3,0.1>
      
    }
    
    //head
    union {
      
      blob {
        threshold 0.05
        sphere {
          <0,0,0>, 0.08, 1
        }
        sphere {
          <0,0.02,0.01>, 0.08, 1
        }
        sphere {
          <0,0.01,-0.05>, 0.03, 1
        }
        cylinder {
          <0,0.02,0>, <0,0.005,-0.075>, 0.01, 1
        }
        sphere {
          <0.04,0.035,-0.035>, 0.02, 1
        }
        sphere {
          <-0.04,0.035,-0.035>, 0.02, 1
        }
        sphere {
          <0.02,0.03,-0.05>, 0.02, -1
        }
        sphere {
          <-0.02,0.03,-0.05>, 0.02, -1
        }
        cylinder {
          <-1,-0.04,-0.06>, <1,-0.04,-0.06>, 0.015, -1
        }
        cylinder {
          <-0.06,0.03,-0.01>, <-0.06,0.03,0.02>, 0.02, 1
        }
        cylinder {
          <0.06,0.03,-0.01>, <0.06,0.03,0.02>, 0.02, 1
        }
        texture { Tex_Skin }
      }
      
      sphere {
        <0,0,0>, 0.02
        
        texture {
          pigment {
            cylindrical
            color_map {
              [0.0 rgb 1]
              [0.9 rgb 1]
              [0.91 rgb <0,1,0>]
              [0.95 rgb <0,1,0>]
              [0.97 rgb 0]
              [1.0 rgb 0]
            }
            scale 0.1
            rotate <90,0,0>
          }
          finish {
            ambient 0.1
            diffuse 0.5
            brilliance 0
            specular 0.9
            roughness 0.001
            reflection {
              0, 1
              fresnel on
            }
            conserve_energy
          }
        }
        interior { ior 1.33 }
        
        translate <-0.02,0.03,-0.05>
      }
      
      //eye patch
      union {
        
        cylinder {
          <0,0,-0.005>, <0,0,0>, 0.02
          rotate <10,-20,0>
          translate <0.04,0.03,-0.05>
        }
        
        torus {
          0.04, 0.002
          rotate <10,-20,-45>
          translate <0.035,0.035,-0.02>
        }
        
        pigment { rgb 0 }
        
      }
      
      //beard
      intersection {
        
        cone {
          <0,-0.1,0>, 0, <0,0,0>, 0.02
          scale <2,1,1>
        }
        
        #local brt = function { pattern { granite scale 0.05 } }
        
        isosurface {
          function { -brt(x,y,z)+0.1+sqrt(pow(10*x,2)+pow(10*z,2)) }
          max_gradient 5
          contained_by { box { <-0.04,-0.1,-0.02>, <0.04,0,0.02> } }
        }
        
        rotate <25,0,0>
        translate <0,-0.05,-0.03>
        
      }
      
      //hat
      union {
        
        prism {
          linear_spline linear_sweep
          0, 0.01, 4,
          <0,0.1>, <sqrt(3)*0.05,-0.05>, <-sqrt(3)*0.05,-0.05>, <0,0.1>
        }
        
        prism {
          linear_spline linear_sweep
          0.01, 0.02, 8,
          <0,0.1>, <sqrt(3)*0.05,-0.05>, <-sqrt(3)*0.05,-0.05>, <0,0.1>,
          <0,0.08>, <sqrt(3)*0.04,-0.04>, <-sqrt(3)*0.04,-0.04>, <0,0.08>
        }
        
        intersection {
          
          sphere {
            <0,0.01,0>, 0.035
          }
          
          plane {
            -y, -0.005
          }
          
          translate <0,0,0.006>
          
        }
        
        rotate <10,0,0>
        translate <0,0.08,0>
        
      }
      
      translate <0,0.42,0.1>
      
    }
    
  }
  
#end

//pirate's ship
#macro PShip(Prt,PSail)
  
  #if (PSail) //pirate's sail?
    #local sail_colour = rgb <0,0,0>;
  #else
    #local sail_colour = rgb <1,0,0>;
  #end
  
  #local Radius =
  sor {
    9,
    <0.01,-0.1>, <0.01,0>, <0.02,0.05>, <0.005,0.1>,
    <0.01,0.15>, <0.005,0.2>, <0.02,0.25>, <0,0.3>, <0, 0.35>
    sturm
  }
  
  #local Tex_Wood_light =
  texture {
    pigment {
      wood
      color_map {
        [0.6 rgb <0.99, 0.70, 0.40>]
        [0.8 rgb <0.70, 0.50, 0.30>]
        [1.0 rgb <0.70, 0.60, 0.40>]
      }
      warp {
        turbulence 0.3
        lambda 3
        omega 0.7
      }
      scale 0.05
      rotate <90,0,0>
    }
    normal {
      granite 0.1
      scale 0.05
    }
    finish {
      ambient 0.1
      diffuse 0.7
      brilliance 3
      specular 0.8
      roughness 0.01
    }
  }
  
  #local Tex_Fabric =
  texture {
    finish {
      ambient 0.1
      diffuse 0.6, 0.4
      brilliance 0.5
      specular 0.3
      roughness 0.005
    }
  }
  
  #local Net_Spline =
  spline {
    cubic_spline
    -1, <0.2,0,1.5>,
    0, <0.15,0,1>,
    2.5, <0.05,2.5,0.15>,
    5, <0,5,0.15>,
  }
  
  #local Net =
  union {
    
    sphere_sweep {
      cubic_spline 4,
      <0,5,0.15>, 0.01,
      <0.05,2.5,0.15>, 0.01,
      <0.15,0,1>, 0.01,
      <0.2,0,2>, 0.01
    }
    
    sphere_sweep {
      cubic_spline 4,
      <0,5,0.15>, 0.01,
      <0,2.5,0.15>, 0.01,
      <0,0,1>, 0.01,
      <0,0,2>, 0.01
    }
    
    sphere_sweep {
      cubic_spline 4,
      <0,5,0.15>, 0.01,
      <-0.05,2.5,0.15>, 0.01,
      <-0.15,0,1>, 0.01,
      <-0.2,0,2>, 0.01
    }
    
    #local i = 1;
    #while (i<20)
      #local h = i*2.5/20;
      #local p = Net_Spline(h);
      cylinder {
        <-p.x,p.y,p.z>, p, 0.01
      }
      #local i = i+1;
    #end
    
    texture {
      pigment {
        wrinkles
        noise_generator 3
        color_map {
          [0.0 rgb <0.5,0.6,0>]
          [0.5 rgb <0.7,0.8,0>]
          [1.0 rgb <1,0.5,0>]
        }
        scale 0.01
      }
      normal {
        wrinkles 0.1
        noise_generator 3
        scale 0.01
      }
      finish {
        ambient 0.1
        diffuse 0.4
        brilliance 5
        specular 0
      }
    }
    
  }
  
  #local Normal_Flag =
  normal {
    gradient x 5
    sine_wave
    frequency 2
  }
    
  union {
    
    intersection {
      
      union {
        
        union {
          
          //keel
          sphere_sweep {
            linear_spline 5,
            <0,-1,2.5>, 0.05
            <0,-1,0>, 0.05,
            <0,-0.5,-2>, 0.05,
            <0,0.5,-2.4>, 0.05,
            <0,1,-2.5>, 0.05
          }
          
          //bar
          difference {
            
            union {
              
              #local b_h = 0.05;
              #local h = -1;
              #local hz = function(y) { pow(y+1,1/3) }
              #local mz = function(y) { max(max(-3.6*y,1.8)-0.2*y,1.7)-0.2*y-4 }
              #local f_x = function(y,z) { 3*sqrt(3)*hz(y)*(mz(y)-z)*(2*z-5)*(2*z-4*mz(y)+5)/pow(abs(2*mz(y)-5),3) }
              #while (h<=0.95)
                prism {
                  linear_spline linear_sweep
                  h, h+b_h, 42,
                  #local i = 0;
                  #while (i<10)
                    #local vz = mz(h+b_h)+i*(2.5-mz(h+b_h))/10;
                    <f_x(h+b_h,vz),vz>
                    #local i = i+1;
                  #end
                  #while (i>=0)
                    #local vz = mz(h+b_h)+i*(2.5-mz(h+b_h))/10;
                    <-f_x(h+b_h,vz),vz>
                    #local i = i-1;
                  #end
                  #local i = 0;
                  #while (i<10)
                    #local vz = mz(h+b_h)+i*(2.5-mz(h+b_h))/10;
                    <f_x(h+b_h,vz)*0.95,vz>
                    #local i = i+1;
                  #end
                  #while (i>=0)
                    #local vz = mz(h+b_h)+i*(2.5-mz(h+b_h))/10;
                    <-f_x(h+b_h,vz)*0.95,vz>
                    #local i = i-1;
                  #end
                }
                #local h = h+b_h+0.002;
              #end
              
            }
            
            //hole
            cylinder {
              <0,0.7,-0.5>, <2,0.7,-0.5>, 0.1
            }
            
          }
          
          //floor 1
          prism {
            linear_spline linear_sweep
            -1, b_h-1, 21,
            #local i = 0;
            #while (i<10)
              #local vz = mz(b_h-1)+i*(2.5-mz(b_h-1))/10;
              <f_x(b_h-1,vz)*0.95,vz>
              #local i = i+1;
            #end
            #while (i>=0)
              #local vz = mz(b_h-1)+i*(2.5-mz(b_h-1))/10;
              <-f_x(b_h-1,vz)*0.95,vz>
              #local i = i-1;
            #end
          }
          
          //floor 2
          difference {
            
            prism {
              linear_spline linear_sweep
              0.5, b_h+0.5, 21,
              #local i = 0;
              #while (i<10)
                #local vz = mz(b_h+0.5)+i*(2.5-mz(b_h+0.5))/10;
                <f_x(b_h+0.5,vz)*0.95,vz>
                #local i = i+1;
              #end
              #while (i>=0)
                #local vz = mz(b_h+0.5)+i*(2.5-mz(b_h+0.5))/10;
                <-f_x(b_h+0.5,vz)*0.95,vz>
                #local i = i-1;
              #end
            }
            
            box {
              <-0.3,0.4,-1.7>, <0.3,b_h+0.6,-1.1>
            }
          }
          
          //floor 3
          intersection {
            
            prism {
              linear_spline linear_sweep
              0.8, b_h+0.8, 21,
              #local i = 0;
              #while (i<10)
                #local vz = mz(b_h+0.8)+i*(2.5-mz(b_h+0.8))/10;
                <f_x(b_h+0.8,vz)*0.95,vz>
                #local i = i+1;
              #end
              #while (i>=0)
                #local vz = mz(b_h+0.8)+i*(2.5-mz(b_h+0.8))/10;
                <-f_x(b_h+0.8,vz)*0.95,vz>
                #local i = i-1;
              #end
            }
            
            plane {
              -z, -0.5
            }
            
          }
          
          texture { Tex_Wood }
          
        }
        
        //steering wheel
        union {
          
          box {
            <-0.1,0,-0.05>, <0.1,0.4,0.05>
            texture { Tex_Wood }
          }
          
          union {
            
            torus {
              0.15, 0.01
              sturm
              rotate <90,0,0>
            }
            
            #local i = 0;
            #while (i<8)
              object {
                Radius
                rotate <0,0,i*360/8>
              }
              #local i = i+1;
            #end
            
            texture { Tex_Wood_light }
            
            translate <0,0.3,0.1>
            
          }
          
          translate <0,b_h+0.8,1>
          
        }
        
        //mast 1, sail 1
        union {
          
          cylinder {
            <0,0,0>, <0,2.5,0>, 0.15
            texture { Tex_Wood rotate <45,0,0> }
          }
          
          cylinder {
            <-1,1,-0.1>, <1,1,-0.1>, 0.05
            texture { Tex_Wood }
          }
          
          cylinder {
            <-0.7,2,-0.1>, <0.7,2,-0.1>, 0.05
            texture { Tex_Wood }
          }
          
          //lookout
          difference {
            
            cone {
              <0,2.5,0>, 0.2, <0,2.7,0>, 0.3
            }
            
            cone {
              <0,2.55,0>, 0.15, <0,2.75,0>, 17/60
            }
            
            texture { Tex_Wood rotate <-45,0,0> }
            
          }
          
          //flag
          union {
            
            cylinder {
              <0,2.55,0.1>, <0,3,0.1>, 0.01
              texture { Tex_Wood }
            }
            
            box {
              <-0.4,2.75,0.09>, <0,3,0.11>
              
              texture {
                Tex_Fabric
                pigment {
                  sail_colour
                }
                normal { Normal_Flag }
              }
            }
            
          }
          
          //nets
          object {
            Net
            rotate <0,70,0>
          }
          object {
            Net
            rotate <0,-70,0>
          }
          
          //sail
          isosurface {
            function { max(sqrt(pow(x,2)+pow(z,2))-1,sqrt(pow(y,2)+pow(z,2))-0.5) }
            contained_by { box { <-1,-0.5,-0.5>, <1,0.5,0> } }
            max_gradient 1
            open
            clipped_by {
              cone {
                <0,-0.5,0>, 1.01, <0,0.5,0>, 0.7
              }
            }
            
            texture {
              Tex_Fabric
              pigment { sail_colour }
            }
            
            scale <1,1,0.5>
            translate <0,1.5,-0.15>
          }
          
          translate <0,b_h+0.5,0>
          
        }
        
        //mast 2, sail 2
        union {
          
          cylinder {
            <0,0,0>, <0,2,0>, 0.15
            texture { Tex_Wood rotate <45,0,0> }
          }
          
          cylinder {
            <-0.7,1,-0.1>, <0.7,1,-0.1>, 0.05
            texture { Tex_Wood }
          }
          
          cylinder {
            <-0.7,2,-0.1>, <0.7,2,-0.1>, 0.05
            texture { Tex_Wood }
          }
          
          sphere {
            <0,2,0>, 0.15
            texture { Tex_Wood }
          }
          
          //nets
          object {
            Net
            scale <0.8,0.8,1>
            rotate <0,70,0>
          }
          object {
            Net
            scale <0.8,0.8,1>
            rotate <0,-70,0>
          }
          
          //sail
          isosurface {
            function { max(sqrt(pow(x,2)+pow(z,2))-0.7,sqrt(pow(y,2)+pow(z,2))-0.5) }
            contained_by { box { <-0.7,-0.5,-0.5>, <0.7,0.5,0> } }
            max_gradient 1
            open
            
            texture {
              Tex_Fabric
              pigment { sail_colour }
            }
            
            scale <1,1,0.5>
            translate <0,1.5,-0.15>
          }
          
          translate <0,b_h+0.5,-0.8>
          
        }
        
        //cannon
        union {
          
          difference {
            
            cylinder {
              <0.9,0.7,-0.5>, <1.5,0.7,-0.5>, 0.09
            }
            
            cylinder {
              <0.8,0.7,-0.5>, <1.6,0.7,-0.5>, 0.08
            }
            
          }
          
          cylinder {
            <1,0.09,0>, <1,0.1,0>, 0.01
            rotate <60,0,0>
            translate <0,0.7,0>
          }
          
          cylinder {
            <1,0.09,0>, <1,0.1,0>, 0.01
            rotate <180,0,0>
            translate <0,0.7,0>
          }
          
          cylinder {
            <1,0.09,0>, <1,0.1,0>, 0.01
            rotate <300,0,0>
            translate <0,0.7,0>
          }
          
          texture {
            pigment { rgb 0 }
            normal {
              bumps 0.01
              scale 0.001
            }
            finish {
              ambient 0.1
              diffuse 0.8
              brilliance 1
              specular 0.8
              roughness 0.01
              metallic 0.5
              reflection {
                0, 0.5
                metallic 0.5
                fresnel on
              }
              conserve_energy
            }
          }
          interior { ior 1.33 }
          
        }
        
        //anchor
        union {
          
          torus {
            1, 0.2
            rotate <-90,0,0>
            translate <0,1,0>
          }
          
          cylinder {
            <0,-3,0>, <0,0,0>, 0.2
          }
          
          cone {
            <0,-1,0>, 0.2, <-1.5,-1,0>, 0
          }
          
          cone {
            <0,-1,0>, 0.2, <1.5,-1,0>, 0
          }
          
          sphere_sweep {
            cubic_spline 5,
            <2,1,0>, 0
            <2,-2,0>, 0.1
            <0,-3,0>, 0.2
            <-2,-2,0>, 0.1
            <-2,1,0>, 0
          }
          
          cone {
            <-2,-2,0>, 0.25, <-2,-1.5,0>, 0
          }
          
          cone {
            <2,-2,0>, 0.25, <2,-1.5,0>, 0
          }
          
          texture {
            pigment { rgb <0.9,1,1> }
            normal {
              bumps
              scale 0.01
            }
            finish {
              ambient 0.1
              diffuse 0.8
              brilliance 1
              specular 0.9
              roughness 0.005
              metallic 0.9
              reflection {
                0.5,0.8
                metallic 0.9
                fresnel on
              }
              conserve_energy
            }
          }
          interior { ior 1.33 }
          
          scale 0.05
          rotate <0,60,0>
          translate <-0.2,0.8,-2.2>
          
        }
        
      }
      
      box {
        <-2,-1,-3>, <3,4,3>
      }
      
      cutaway_textures
    
    }
    
    #if (Prt)
      //pirate
      object {
        Pirate(array[2] {<0,0,45>,<100,20,180>},array[2] {<-20,0,-45>,<110,0,45>})
        scale 0.5
        translate <0,b_h+1.105+0.025*cos(pi/10),1.2>
      }
    #end
    
  }
  
#end

#version ov;