POV-Ray : Newsgroups : povray.binaries.images : Toward a less-lame rand() function. : Toward a less-lame rand() function. Server Time
31 Jul 2024 18:26:46 EDT (-0400)
  Toward a less-lame rand() function.  
From: gregjohn
Date: 15 May 2009 07:55:00
Message: <web.4a0d5729a7098c1c34d207310@news.povray.org>
The neatly ordered, predictable pattern of red dots in the top half of the image
are generated with povray's rand() function.  They demonstrate what you get if
you cause a monotonic increase in the seed value.  Once I had a project
"ruined" by this predictable pattern because I was exploring some parameter
space via use of the #declare RSEED=seed(frame_number).

The green dots below represent my best attempt so far to create something worthy
of the title "random function".   It requires one first to set an "aseed" value
between 0 and 1, but this aseed *may* increase monotonically, like #declare
aseed=(frame_number+0.1)/(final_frame+0.1);

#macro randoo()
#declare aseed=pi/(aseed)+pi/(1+aseed);
#declare aseed=aseed*10000-int(10000*aseed);
(aseed)
#end


And here is the complete (mess!) of code that generated my image:

#include"transforms.inc"

#macro Reorient(Axis1,Axis2)//john vansickle
                #local vX1=vnormalize(Axis1);
                #local vX2=vnormalize(Axis2);
                #local vY=vnormalize(vcross(vX1,vX2));
                #local vZ1=vnormalize(vcross(vX1,vY));
                #local vZ2=vnormalize(vcross(vX2,vY));
                matrix < vX1.x, vY.x,vZ1.x, vX1.y,vY.y,vZ1.y, vX1.z,vY.z, vZ1.z,
0,0,0 >
                matrix < vX2.x,vX2.y,vX2.z,  vY.x,vY.y, vY.z, vZ2.x,vZ2.y,vZ2.z,
0,0,0 >
              #end

#declare iwih=image_width/image_height;

#declare camang=45;

#declare camloke=-100*z;
#declare azee=0.5*iwih/tan(camang/2*pi/180);

#declare camlook_at=0;
#declare seedirn= camlook_at-camloke+0.000001;
#declare cameratransform=transform{ Reorient (z,seedirn*<1,0,1.001>)
Reorient(seedirn*<1,0,1.001>,seedirn) translate camloke}

camera {
  direction z*azee
  up y
  right     x*image_width/image_height
  transform{cameratransform}
 }

#declare RRR=seed(frame_number);   //standard way of declaring a seed
#declare aseed=0.335;//mod((frame_number+1)/100,1);

#macro randoo()                     //a new, truly random number generator.
#declare aseed=pi/(aseed)+pi/(1+aseed);
#declare aseed=aseed*10000-int(10000*aseed);
(aseed)
#end

#declare a=randoo();
#declare nmax=3980;
#declare oldway_oldend=rand(RRR);
#declare newway_oldend=randoo();//rand(aseed2);


#declare n=0;
#while(n<nmax)

#declare RRR=seed(n);
#declare aseed=mod((n+1)/nmax,1);


#declare oldway_newend =rand(RRR);
#declare newway_newend=randoo();

sphere{<iwih*(n+1)/nmax-iwih/2,0.5*(oldway_newend),azee>
,0.005
 pigment{red 1}finish{ambient rgb 1}
 transform{cameratransform}
 }

sphere{<iwih*(n+1)/nmax-iwih/2,0.5*(newway_newend)-0.5,azee>
,0.005
 pigment{green 0.5}finish{ambient rgb 1}
 transform{cameratransform}
 }

#declare oldway_oldend=oldway_newend;
#declare newway_oldend=newway_newend;

#declare n=n+1;
#end

box{<-iwih/2,-0.5,azee+1>,<iwih/2,0.5,azee+0.051> pigment{rgb 1}finish{ambient
rgb 1}
 transform{cameratransform}}


Post a reply to this message


Attachments:
Download 'zrandtest11.png' (137 KB)

Preview of image 'zrandtest11.png'
zrandtest11.png


 

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