POV-Ray : Newsgroups : povray.text.scene-files : Source code for "Iso-tori" Server Time
22 Dec 2024 22:47:50 EST (-0500)
  Source code for "Iso-tori" (Message 1 to 1 of 1)  
From: Tor Olav Kristensen
Subject: Source code for "Iso-tori"
Date: 27 May 2002 20:01:32
Message: <3CF2C822.82177E55@hotmail.com>
Here is the source code for the "Iso-tori" image that I
posted to the povray.binarires.images group 24. Jan. 2002.

news://news.povray.org/3C508843.A7B53416%40hotmail.com

Note that the tone range for the image I posted is
different from the one that this code will generate.

This is because I adjusted the tone range for that image
with Micrografx Picture Publisher prior to posting.

To get colour tones that are somewhat similar, uncomment
the assumed_gamma statement and the *1.5 part in the end
of the color line of the light source.


Tor Olav


// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// Copyright 2002 by Tor Olav Kristensen
// Email: t o r _ o l a v _ k [ a t ] h o t m a i l . c o m
// http://hjem.sol.no/t-o-k/povray
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

#version 3.5;

#include "colors.inc"
#include "textures.inc"
#include "functions.inc"

global_settings {
//  assumed_gamma 2.4
  ambient_light color White
}

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

#macro Tilt(vTilt)

  #local v0 = vnormalize(vTilt);
  #local X = v0.x;
  #local Y = v0.y;
  #local Z = v0.z;
  #if (abs(Y) = 1)
    #if (Y = 1)
      #local TiltTrans = transform { }
    #else
      #local TiltTrans = transform { rotate 180*z }
    #end // if
  #else
    #local T = (Y - 1)/(X^2 + Z^2);
    #local TiltTrans =
      transform {
        matrix <Y-T*Z*Z,-X,T*X*Z,X,Y,Z,T*X*Z,-Z,Y-T*X*X,0,0,0>
      }
  #end // if

  transform { TiltTrans }

#end // macro Tilt


#macro TransformFunction(Fn, Transform)

  #local TT = function { transform { Transform inverse } }

  function { Fn(TT(x, y, z).x, TT(x, y, z).y, TT(x, y, z).z) }

#end // macro TransformFunction


#declare SquashFn =
  function(f, s) { select(s, -1, 1)*(1/(1 + exp(-abs(s)*f)) - 1) }

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

#declare MajR = 20;
#declare MinR = 6;

#declare MicRs = 0.8;
#declare MicRb = MicRs + 0.3;

#declare NrOfRings = 4;

#declare TorusFnArray1 = array[NrOfRings]
#declare TorusFnArray2 = array[NrOfRings]
#declare TorusFnArray3 = array[NrOfRings]
#declare TorusFnArray4 = array[NrOfRings]

#declare Cnt = 0;
#while (Cnt < NrOfRings)
  #declare Angle = Cnt/NrOfRings*360;

  #declare TorusFnArray1[Cnt] =
    TransformFunction(
      function { f_torus(x, y, z, MajR, MicRb) },
      transform {
        Tilt(< MinR,  MajR,  0>)
        translate MinR*z
        rotate Angle*y
      }
    )

  #declare TorusFnArray2[Cnt] =
    TransformFunction(
      function { f_torus(x, y, z, MajR, MicRb) },
      transform {
        Tilt(<-MinR,  MajR,  0>)
        translate MinR*z
        rotate Angle*y
      }
    )

  #declare TorusFnArray3[Cnt] =
    TransformFunction(
      function { f_torus(x, y, z, MajR, MicRs) },
      transform {
        Tilt(< MinR,  MajR,  0>)
        translate MinR*z
        rotate Angle*y
      }
    )

  #declare TorusFnArray4[Cnt] =
    TransformFunction(
      function { f_torus(x, y, z, MajR, MicRs) },
      transform {
        Tilt(<-MinR,  MajR,  0>)
        translate MinR*z
        rotate Angle*y
      }
    )

  #declare Cnt = Cnt + 1;
#end // while

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

isosurface {
  function {
    SquashFn(f_torus(x, y, z, MajR, MinR), 6)
    #declare Cnt = 0;
    #while (Cnt < NrOfRings)
      +SquashFn(TorusFnArray1[Cnt](x, y, z), -6)
      +SquashFn(TorusFnArray2[Cnt](x, y, z), -6)
      #declare Cnt = Cnt + 1;
    #end // while
  }
  threshold -0.5
  max_gradient 5
  accuracy 1E-8
  contained_by {
    box {
     -<MajR + MinR, MinR, MajR + MinR>,
      <MajR + MinR, MinR, MajR + MinR>
    }
  }
  texture { New_Penny }
}

isosurface {
  function {
    #declare Cnt = 0;
    #while (Cnt < NrOfRings)
      +SquashFn(TorusFnArray3[Cnt](x, y, z), 6)
      +SquashFn(TorusFnArray4[Cnt](x, y, z), 6)
      #declare Cnt = Cnt + 1;
    #end // while
  }
  threshold -0.5
  max_gradient 5
  accuracy 1E-8
  contained_by {
    box {
     -<MajR + MinR + MicRs, MinR + MicRs, MajR + MinR + MicRs>,
      <MajR + MinR + MicRs, MinR + MicRs, MajR + MinR + MicRs>
    }
  }
  texture { Soft_Silver }
}

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

light_source {
  <-5, 2, -8>*40
  color White // *1.5
  shadowless
}

sky_sphere {
  pigment {
    gradient y
    color_map {
      [ 0 color rgb <0.7, 0.7, 1.0> ]
      [ 1 color rgb <0.0, 0.0, 0.5> ]
    }
  }
}

camera {
  location <0, 10, -10>*5
  look_at <0, -2, 0>
}

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7


Post a reply to this message

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