POV-Ray : Newsgroups : povray.binaries.scene-files : Styrofoam Spring Server Time
1 Sep 2024 18:14:49 EDT (-0400)
  Styrofoam Spring (Message 1 to 2 of 2)  
From: Tim Attwood
Subject: Styrofoam Spring
Date: 16 Mar 2005 04:34:57
Message: <4237fdc1$1@news.povray.org>
// Persistence of Vision Ray Tracer Scene Description File
// File: spring_demo.pov
// Vers: 3.6
// Desc: Mesh Spring Scene Example
// Date: 3/15/2005
// Auth: Tim Attwood
//

#version 3.5;

#include "colors.inc"
#include "metals.inc"
#include "finish.inc"
#include "skies.inc"

global_settings {
  assumed_gamma 1.0
  max_trace_level 50

}

// ---- Background ------------------------------------

camera {
  location  <0.0, -0.7, -2.0>
  direction 1.5*z
  right     x*image_width/image_height
  look_at   <0.0, -0.5,  0.0>
}

sky_sphere {
  pigment {
    gradient y
    color_map {
      [0.0 Red]
      [0.2 Blue]
      [0.4 Black]
      [0.6 Blue]
      [0.8 Red]
      [1.0 Yellow]
    }
  }
}
object {O_Cloud2}

light_source {
  0*x                 // light's position (translated below)
  color rgb 1.0       // light's color
  area_light
  <8, 0, 0> <0, 0, 8> // lights spread out across this distance (x * z)
  4, 4                // total number of lights in grid (4x*4z = 16 lights)
  adaptive 0          // 0,1,2,3...
  jitter              // adds random softening of light
  circular            // make the shape of the light circular
  orient              // orient light
  translate <-30, 30, -30>   // <x y z> position of light
}

light_source {
  <0, 0, 0>            // light's position (translated below)
  color rgb <0.5, 0.5, 1>*0.1  // light's color
  translate <30, 30, -30>
}

// ----- Macros ----------------------------------- 
#macro BoxSpring (BX BY Xlen Xcoil Rez)   // width, thickness, length, coils 
per unit length, resolution
#declare Xval=0;
#declare Xlast=Xval;
mesh {
 #declare BSai = 
<Xlast/6.2832,sin(Xlast*Xcoil)*(1-BY),cos(Xlast*Xcoil)*(1-BY)>;
 #declare BSbi = 
<(Xlast/6.2832)+BX,sin(Xlast*Xcoil)*(1-BY),cos(Xlast*Xcoil)*(1-BY)>;
 #declare BSao = <Xlast/6.2832,sin(Xlast*Xcoil),cos(Xlast*Xcoil)>;
 #declare BSbo = <(Xlast/6.2832)+BX,sin(Xlast*Xcoil),cos(Xlast*Xcoil)>;
 triangle { BSai, BSao, BSbi }
 triangle { BSbo, BSao, BSbi }
 #while (Xval <= 6.2832*(Xlen-BX) )
   #if (Xval != Xlast)
    #declare BSai = 
<Xlast/6.2832,sin(Xlast*Xcoil)*(1-BY),cos(Xlast*Xcoil)*(1-BY)>;
    #declare BSbi = 
<(Xlast/6.2832)+BX,sin(Xlast*Xcoil)*(1-BY),cos(Xlast*Xcoil)*(1-BY)>;
    #declare BSci = 
<Xval/6.2832,sin(Xval*Xcoil)*(1-BY),cos(Xval*Xcoil)*(1-BY)>;
    #declare BSdi = 
<(Xval/6.2832)+BX,sin(Xval*Xcoil)*(1-BY),cos(Xval*Xcoil)*(1-BY)>;
    #declare BSao = <Xlast/6.2832,sin(Xlast*Xcoil),cos(Xlast*Xcoil)>;
    #declare BSbo = <(Xlast/6.2832)+BX,sin(Xlast*Xcoil),cos(Xlast*Xcoil)>;
    #declare BSco = <Xval/6.2832,sin(Xval*Xcoil),cos(Xval*Xcoil)>;
    #declare BSdo = <(Xval/6.2832)+BX,sin(Xval*Xcoil),cos(Xval*Xcoil)>;
    #declare BSe = <Xlast/6.2832,0,0>;
    #declare BSf = <(Xval/6.2832)+BX,0,0>;
    triangle { BSai, BSci, BSbi }
    triangle { BSdi, BSci, BSbi }
    triangle { BSao, BSco, BSbo }
    triangle { BSdo, BSco, BSbo }
    triangle { BSao, BSai, BSco }
    triangle { BSci, BSai, BSco }
    triangle { BSbo, BSbi, BSdo }
    triangle { BSdi, BSbi, BSdo }
   #end
  #declare Xlast=Xval;
  #declare Xval = Xval + Rez; // resolution (0.01)
 #end
 #declare BSai = 
<Xlast/6.2832,sin(Xlast*Xcoil)*(1-BY),cos(Xlast*Xcoil)*(1-BY)>;
 #declare BSbi = 
<(Xlast/6.2832)+BX,sin(Xlast*Xcoil)*(1-BY),cos(Xlast*Xcoil)*(1-BY)>;
 #declare BSao = <Xlast/6.2832,sin(Xlast*Xcoil),cos(Xlast*Xcoil)>;
 #declare BSbo = <(Xlast/6.2832)+BX,sin(Xlast*Xcoil),cos(Xlast*Xcoil)>;
 triangle { BSai, BSao, BSbi }
 triangle { BSbo, BSao, BSbi }
}
#end

#macro styrofoam(Obj Extent Beadsize Num M) // Object, Extent of beads, Bead 
size, Number of beads, mode
union {
   #local Count = Num;
   #local R1 = seed(0);
   #local DV = <0,0,Extent>;
   #if (M=0)    // spherical
      #while (Count != 0)
         #local Norm = <0,0,0>;
         #local DV = vrotate(DV,<360*rand(R1),360*rand(R1),360*rand(R1)>);
         #local Berry = trace(Obj,DV,-DV,Norm);
         #local Count = Count - 1;
         #if (vlength(Norm)!=0)
            sphere {<0,0,0>, Beadsize translate Berry }
         #end
      #end
   #else // random
      #local fail = 0;
      #while ( (Count != 0) & (fail < 1000000 ))
         #local Norm = <0,0,0>;
         #local H1 = 
<2*Extent*rand(R1)-Extent,2*Extent*rand(R1)-Extent,Extent>;
         #local H2 = 
<2*Extent*rand(R1)-Extent,2*Extent*rand(R1)-Extent,-Extent>;;
         #local R2 = 360*rand(R1);
         #local H1 = vrotate(H1,<0,R2,0>);
         #local H2 = vrotate(H2,<0,R2,0>);
         #local Berry = trace(Obj,H1,H2,Norm);
         #if (vlength(Norm)!=0)
            sphere {<0,0,0>, Beadsize translate Berry }
            #local Count = Count - 1;
            #local fail = 0;
         #else
            #local fail = fail + 1;
         #end
      #end
   #end
   pigment{White}
}
#end

// ----- objects -----------------------------------


#declare TBox = box {<-1,-1,-1>,<1,1,1>  // target box for styrofoam
   rotate <45,0,45>
   scale 0.15
};

#declare TSpring = union{BoxSpring(0.2 0.2 2.0 1.5 0.001) translate 
<0,-1,0>};


#declare styrobox = styrofoam(TBox, 2, 0.0125, 4000, 1);
#declare styrospring = styrofoam(TSpring, 2.1, 0.04166, 8000, 1);

#declare odd = union { // a metal coil and a floating styrofoam box
   object {
      TSpring
      scale 0.3
      rotate <0,0,90>
      translate <0,-1,0>
      texture{T_Chrome_2A}
   }
   object {
      styrobox
      translate <0,-0.25,0>
      pigment {White}
   }
};

#declare odder = union { // a metal coil and a floating styrofoam box
   object {
      styrospring
      translate <0,1,0>
      scale 0.3
      rotate <0,0,90>
      translate <0,-1,0>
      pigment {White}
   }
   object {
      TBox
      translate <0,-0.25,0>
      texture{T_Chrome_2A}
   }
};


// ----- Scene ----------------------------------

plane {
  y, -1
  texture {
     pigment { checker White Black }
     finish{Shiny}
  }
}

object {odder}
object {odd rotate <0,60,0> translate <-1,0,1>}
object {odd rotate <0,-60,0> translate < 1,0,1>}


Post a reply to this message

From: Burki
Subject: Re: Styrofoam Spring
Date: 3 May 2005 11:55:01
Message: <web.42779e0d2990fd68d61e8c370@news.povray.org>
This one I really like !

Did you see the tiny little whole in the middle spring?
 - Someone must have picked out one of the styro bubbles !

Burki


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.