#version 3.7;

global_settings {
  assumed_gamma 1
  photons {
    spacing 0.01
    jitter 0
    autostop 0
  }
  radiosity {
    pretrace_start 0.08
    pretrace_end   0.04
    count 5

    nearest_count 5
    error_bound 1.8
    recursion_limit 3
    media on

    low_error_factor 0.5
    gray_threshold 0.0
    minimum_reuse 0.015
    brightness 0.75

    adc_bailout 0.005
    normal on
  }
}

camera {
  perspective
  location    <0,400*sqrt(3)/27,0>
  direction   <0,-1,0>
  right       x*image_width/image_height
  sky         <0,0,1>
  angle       60
  look_at     <0,0,0>
}

light_source {
  <0,0,0>
  color rgb <2,2,1>
  
  photons {
    refraction on
    reflection on
  }
  
  translate <400,800,1000>
}

sky_sphere {
  pigment {
    gradient y
    cubic_wave
    color_map {
      [0.0 rgb 0]
      [0.5 rgb <0.4,0.8,1>]
      [1.0 rgb <0.1,0.2,0.9>]
    }
    scale 2
    translate <0,-1,0>
  }
}

#macro PS_pos(time)
  <6,0,-10>*time*(pow(time,2)-3*time+3)/3+<-2,0,5>
#end

#macro AS_pos(time,a)
  #if (a=1) //Rotation
    #if ((3*time)<2)
      <0,0,0>
    #else
      <0,-125,0>*pow(3*time-2,2)*(7-6*time)
    #end
  #else //Position
    #local norm = <0,0,-10/3>*time+<3.5,0,5>;
    #if (time<0.5)
      norm
    #else
      #local ow = <4.6,0,-6.55>;
      (norm*(2-2*time)+(ow*pow((time-0.5)*2,2)))
    #end
  #end
#end

#macro VS_pos(time,a,n)
  #if (a=1) //Rotation
    <0,atan2(16*time-8*pow(time,2),16*pow(time,2)-24*time+8)*180/pi-180,0>+<0,-80+45*n,0>
  #else //Position
    vrotate(
      <-8*pow(time,3)/3+8*pow(time,2)-16/3,0,16*pow(time,3)/3-12*pow(time,2)+8*time-28/3>,
      <0,-80+45*n,0>
    )
  #end
#end

#local Water_norm = function {
  pattern {
    granite
    sine_wave
    warp {
      turbulence 0.5
    }
    scale 10
  }
}

#local Waves_Ship = function(x,y,z,a,b,c) { 10*cos(5*pi*(sqrt(pow(x-a,2)+pow(y,2)+pow(z-b,2))-0.1*c)) }

#local Waves_s1 = function(x,y,z,a,b,c,d) { exp(-(pow(x-a,2)+pow(y,2)+pow(z-b,2))/(1.81*(c-d+0.1)))*Waves_Ship(x,y,z,a,b,c-d)*pow(4*(c-d),1-4*(c-d)) }

#local incr = 0.1;
#local posxP = array[floor(1/incr)+2];
#local poszP = array[floor(1/incr)+2];
#local posxA = array[floor(1/incr)+2];
#local poszA = array[floor(1/incr)+2];
#local posxV = array[floor(1/incr)+2][10];
#local poszV = array[floor(1/incr)+2][10];
#for (j,-1,floor(1/incr),1)
  #local posxP[j+1] = ((PS_pos(j*incr)).x);
  #local poszP[j+1] = ((PS_pos(j*incr)).z);
  #local posxA[j+1] = ((AS_pos(j*incr,0)).x);
  #local poszA[j+1] = ((AS_pos(j*incr,0)).z);
  #for (k,0,9,1)
    #local posxV[j+1][k] = ((VS_pos(j*incr,0,k)).x);
    #local poszV[j+1][k] = ((VS_pos(j*incr,0,k)).z);
  #end
#end

#local Waves_full = function(x,y,z) { Water_norm(x,y,z)+
  #for (i,-1,floor(1/incr),1)
    Waves_s1(x,y,z,posxP[i+1],poszP[i+1],1,i*incr)+
    Waves_s1(x,y,z,posxA[i+1],poszA[i+1],1,i*incr)+
    #for (l,0,9,1)
      Waves_s1(x,y,z,posxV[i+1][l],poszV[i+1][l],1,i*incr)+
    #end
  #end 0
}

plane {
  y, 0
  
  material {
    texture {
      pigment { rgbf <0.9,0.9,1,0.9> }
      normal {
        function { Waves_full(x,y,z) } 0.1
      }
      finish {
        ambient 0.1
        diffuse 0.7
        brilliance 0.1
        specular 1
        roughness 0.005
        reflection {
          0.3, 1
          fresnel on
        }
        irid {
          0.25
          thickness 0.1
          turbulence 0.5
        }
        conserve_energy
      }
    }
    interior {
      ior 1.33
    }
  }
  
  photons {
    target 10000
    reflection on
    refraction on
  }
  
  hollow on
}

#include "Ship minimum.inc"

object {
  PShip(yes,yes)
  translate PS_pos(1)
}

object {
  PShip(no,no)
  rotate AS_pos(1,1)
  translate AS_pos(1,0)
}

#local i = 0;
#while (i<8)
  
  #if (i!=1) //leave out ship no. 1
    object {
      PShip(no,no)
      rotate VS_pos(1,1,i)
      translate VS_pos(1,0,i)
    }
  #end
  
  #local i = i+1;
#end