POV-Ray : Newsgroups : povray.text.scene-files : Pseudo-random stream seed incrementor Server Time
19 May 2024 15:59:52 EDT (-0400)
  Pseudo-random stream seed incrementor (Message 1 to 1 of 1)  
From: Dave Blandston
Subject: Pseudo-random stream seed incrementor
Date: 6 Mar 2010 14:30:01
Message: <web.4b92ac3bf382b5cccba3fb0f0@news.povray.org>
Hi there,

Recently I worked on a scene that I just couldn't pick good colors for, so I
decided to let POV pick random colors. I kept incrementing the random stream
seed and re-rendering until I was happy with the colors POV picked. I did the
same thing with some texture transformation values. I quickly realized it was
tedious to manually change the seed value so here's some code in case you find
yourself in the same situation. I hope someone finds this useful!

Regards,
Dave Blandston
--------------------------------------

//Set the following four variables to control how POV-Ray selects a
pseudo-random stream seed when you render your scene.
//NOTE: Using this code will create a file called "Seed.txt" in your current
directory.

#local UseRandomness = 1;     //Set to "yes" to use random settings, or "no" to
use your pre-defined settings.
#local UseLastRandomSeed = 0; //Set to "yes" to re-use the last seed value. For
example, if you want to see your current selection at a higher resolution.
#local RandomSeed = 91;       //Whatever your favorite seed is up to this point.
This value must be used in conjunction with the "InitializeFile" setting.
#local InitializeFile = 0;    //Set to "yes" to initialize the seed file with
whatever value "RandomSeed" is set to. Set to "no" to cause POV-Ray to use a NEW
pseudo-random stream seed every time you render your scene.

#if (UseRandomness & !InitializeFile & file_exists ("Seed.txt"))
   #fopen RandomSeedFile "Seed.txt" read
   #read (RandomSeedFile, RandomSeed)
   #fclose RandomSeedFile
#end //#if

#if (!UseLastRandomSeed & !InitializeFile)
   #local RandomSeed = RandomSeed + 1;
#end //#if

#local Randomizer = seed (RandomSeed);

#if (UseRandomness)
   #fopen RandomSeedFile "Seed.txt" write
   #write (RandomSeedFile, RandomSeed)
   #fclose RandomSeedFile
#end //#if

//Everything after this is just a sample scene...

#include "colors.inc"

#local PreDefinedColor1 = color Black;
#local PreDefinedColor2 = color White;

camera {
   location <0, 0, -4>
   look_at <0, 0, 0>
} //camera

light_source {<15, -20, -200> color White * 1.6}

#local RandomColor = texture {
   pigment {
      gradient y
      #if (UseRandomness)
         #local C1R = rand (Randomizer);
         #local C1G = rand (Randomizer);
         #local C1B = rand (Randomizer);
         #local C2R = rand (Randomizer);
         #local C2G = rand (Randomizer);
         #local C2B = rand (Randomizer);
         #local Color1 = color <C1R, C1G, C1B>;
         #local Color2 = color <C2R, C2G, C2B>;
         #debug concat ("\n\nRandomSeed: ", str (RandomSeed, 0, 0))
         #debug concat ("\n\nColor 1: <", str (C1R, 0, 4), ", ", str (C1G, 0,
4), ", " str (C1B, 0, 4), ">\n")
         #debug concat ("\nColor 2: <", str (C2R, 0, 4), ", ", str (C2G, 0, 4),
", " str (C2B, 0, 4), ">\n\n\n")
      #else
         #local Color1 = color PreDefinedColor1;
         #local Color2 = color PreDefinedColor2;
      #end //#if
      color_map {
         [0 color Color1]
         [1 color Color2]
      } //color_map
   } //pigment
   scale 2
   translate 1 * y
} //texture

sphere {0, 1 texture {RandomColor}}


Post a reply to this message

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