POV-Ray : Newsgroups : povray.text.scene-files : "Fibonacci Stones" source code Server Time
8 Jul 2024 10:33:22 EDT (-0400)
  "Fibonacci Stones" source code (Message 1 to 1 of 1)  
From: Tor Olav Kristensen
Subject: "Fibonacci Stones" source code
Date: 5 Sep 2000 21:19:24
Message: <39B59A50.66F1BAA7@online.no>
Below is the source code for an image I posted 5. September to the
povray.binaries.images news group; "Fibonacci Stones":

news://news.povray.org/39B44A76.2ECBA98A%40online.no
(The image shows my "AnitBlobs" in a Fibonacci pattern)

For this image I borrowed some code from Alf Peake's post
"Golden Ratio" to this group 31. August:

news://news.povray.org/39ad9be0%40news.povray.org


Tor Olav


// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// Copyright 2000 by Tor Olav Kristensen
// mailto:tor### [at] hotmailcom
// http://www.crosswinds.net/~tok/tokrays.html
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

#version 3.1;
#include "colors.inc"

#default {
  finish {
    phong 0.6
    phong_size 100
    diffuse 0.6
  }
}

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

#macro Tilt(Thing, Vector)

  #local xAngle = (Vector.z < 0 ? -1 : 1)*
                  degrees(acos(vnormalize((x + z)*Vector).x));
  #local yAngle = degrees(acos(vnormalize(Vector).y));

  object {
    Thing
    rotate  xAngle*y
    rotate -yAngle*z
    rotate -xAngle*y
  }

#end // macro Tilt


#macro AntiBlobs(CtrArray, RadArray, StrArray, Trh, BlbArray)

  #local NrOfBlobs = dimension_size(CtrArray, 1);
  #local CntA = 0;
  #while (CntA < NrOfBlobs)
    #local CtrA = CtrArray[CntA];
    #local RadA = RadArray[CntA];
    #local StrA = StrArray[CntA];
    #declare BlbArray[CntA] =
      blob {
        threshold Trh
        sphere {
          CtrA, RadA
          strength StrA
        }
        #local CntB = 0;
        #while (CntB < NrOfBlobs)
          #if (CntA != CntB)
            #local CtrB = CtrArray[CntB];
            #local RadB = RadArray[CntB];
            #local Dist = vlength(CtrB - CtrA);
            #if (Dist < RadA + RadB)
              #local PowA = pow(1 - pow(Dist/2/RadA, 2), 2);
              #local PowB = pow(1 - pow(Dist/2/RadB, 2), 2);
              #local NStrB = -abs((StrA*PowA - Trh)/PowB);
              sphere {
                CtrB, RadB
                strength NStrB
              }
            #end // if
          #end // if
          #local CntB = CntB + 1;
        #end // while
      }
    #local CntA = CntA + 1;
  #end // while

#end // macro AntiBlobs

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// Some of the code here are borrowed from Alf Peake

#declare phi = (sqrt(5) - 1)/2;
#declare Inc = phi*360;
#declare Offset = 0.5;
#declare MaxCount = 400; // Number of "stones"

#declare CenterArray = array[MaxCount]
#declare RadiusArray = array[MaxCount]
#declare StrengthArray = array[MaxCount]
#declare BlobArray = array[MaxCount]

#declare Cnt = 0;
#while (Cnt < MaxCount)
  #declare Rad = sqrt(Cnt + Offset)/10;
  #declare CenterArray[Cnt] = vrotate(z*Rad, y*Cnt*Inc);
  #declare RadiusArray[Cnt] = 0.15;
  #declare StrengthArray[Cnt] = 1;
  #declare Cnt = Cnt + 1;
#end // while


#declare Threshold = 0.08;

AntiBlobs(CenterArray, RadiusArray, StrengthArray, Threshold, BlobArray)



// Some code borrowed from POV-Ray's "stones1.inc" file

#declare Turb = 0.6;

#declare GranitePigment =
pigment {
  marble
  turbulence Turb
  color_map {
    [ 0.000 color rgbf <0.894, 0.886, 0.886, 0.000> ]
    [ 0.154 color rgbf <0.745, 0.745, 0.753, 0.000> ]
    [ 0.308 color rgbf <0.902, 0.902, 0.859, 0.000> ]
    [ 0.444 color rgbf <0.729, 0.706, 0.694, 0.000> ]
    [ 0.615 color rgbf <0.588, 0.592, 0.635, 0.000> ]
    [ 0.803 color rgbf <0.608, 0.616, 0.659, 0.000> ]
    [ 1.000 color rgbf <0.894, 0.886, 0.886, 0.000> ]
  }
}


#declare Granite1 =
texture {
  pigment { GranitePigment }
  finish {
    ambient 0.2
    crand 0.03
  }
}


#declare Granite2 =
texture {
  normal {
    marble
    turbulence Turb
    bump_size 0.4
  }
  pigment { GranitePigment }
  finish {
    ambient 0.2
    crand 0.17
  }
}


// Release the blobs and texture them

union {
  #declare PtCnt = 0;
  #while (PtCnt < MaxCount)
    object {
      BlobArray[PtCnt]
      texture {
        marble
        turbulence Turb
        texture_map {
          [ 0.70 Granite1 ]
          [ 0.80 Granite2 ]
        }
        scale 0.2
      }
      translate CenterArray[PtCnt]*0.1 // To move them a little apart
    }
    #declare PtCnt = PtCnt + 1;
  #end // while
}

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// Lights, background and camera

sky_sphere {
  pigment {
    marble
    turbulence 1.2
    color_map {
      [ 0 color rgb <0, 1, 2>/8 ]
      [ 1 color rgb <0, 0, 1>/2 ]
    }
    scale 0.5
  }
}

#declare AreaLight1 =
light_source {
  50*y
  color White
  area_light 10*x, 10*z, 3, 3
  jitter
}

#declare AreaLight2 =
light_source {
  50*y
  color Red/4
  area_light 10*x, 10*z, 3, 3
  jitter
}

Tilt(AreaLight1, <1, 1/2, 1>)
Tilt(AreaLight2, <-1, 1, 1>)

camera {
  location <0, 5, 0>
  angle 40
  look_at <0, 0, 0>
}

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


Post a reply to this message

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