POV-Ray : Newsgroups : povray.text.scene-files : Gaussian random numbers : Re: Gaussian random numbers Server Time
8 Jul 2024 12:09:35 EDT (-0400)
  Re: Gaussian random numbers  
From: Michael Zier
Date: 7 Jul 2001 06:57:01
Message: <3b46eafd$1@news.povray.org>
Sorry, I mailed this direct to you. I just misused Outlook...

How about this:

#macro Gauss2(RS,w)
 #local i=w;
 #local r=0;
 #while (i>0)
  #local r=r+rand(RS)/w;
  #local i=i-1;
 #end
 r
#end

RS... Random Seed
w... "width" of the distribution (the higher w, the narrower the dist.)

produces values between 0 and 1, with the maximum at 0.5

Here's a simple test scene (add the above macro at the top):

#declare spectrum
=array[30]{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}

#declare i=0;
#declare R=seed(1712942);
#while(i<10000)
 #declare r=Gauss2(R,2)*30;
 #declare spectrum[int(r)]=spectrum[int(r)]+1/50;
 #declare i=i+1;
#end

#declare _x=0;
#while (_x<30)
 box{
  <_x,0,-0.5>,<_x+1,spectrum[_x],0.5>

ment{ 
   color rgb <1,0.2,0.2>
  }                     
  finish{
   ambient 0.2
   specular 1
   brilliance 0.6
   roughness 0.1
  }
 }
 #declare _x=_x+1;
#end  
                
                
camera {
 location <15,50,-80>
 look_at <15,30,0>
}                

light_source {
 <-20,50,-50>*100
 color rgb 1
}


Post a reply to this message

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