POV-Ray : Newsgroups : povray.advanced-users : Something more theoretical.... : Re: Something more theoretical.... Server Time
29 Jul 2024 12:27:41 EDT (-0400)
  Re: Something more theoretical....  
From: Bonsai
Date: 17 Apr 2002 02:56:28
Message: <3cbd1c9c$1@news.povray.org>
"Jan Walzer" <jan### [at] lzernet> schrieb im Newsbeitrag
news:3cbc990e@news.povray.org...
> You say, that I should first place all the spheres in a grid, and then
jitter this
> to make a random distribution ? ... sounds interesting ...

And it works very well. Look in p.b.i for my test render of 50.000 spheres.

I made a array of 500x500 squares. In every square there can only be 1
sphere. After detecting a free square I translated the sphere randomly
within the square and marked the square as loaded. That's it. Here is some
code:

// Initialising the array
#declare gitter = array[501][501];
#declare array_help_x = 0;
#declare array_help_z = 0;
#while (array_help_x < 501)
        #while (array_help_z < 501)
                #declare gitter[array_help_x][array_help_z] = 0;
                #declare array_help_z = array_help_z + 1;
        #end
        #declare array_help_x = array_help_x + 1;
        #declare array_help_z = 0;
#end

#declare i = 1;
#declare zufall = seed(123456);

#while (i < 50000)
        // Find a square to start
        #declare neu_x = floor(500*rand(zufall)+0.5);
        #declare neu_z = floor(500*rand(zufall)+0.5);

        // If the square is loaded, find another one
        #while (gitter[neu_x][neu_z] = 1)
                #declare neu_x = floor(500*rand(zufall)+0.5);
                #declare neu_z = floor(500*rand(zufall)+0.5);
        #end

        // Mark the square as loaded
        #declare gitter[neu_x][neu_z] = 1;
        // Random radius
        #declare neu_radius = 0.5*rand(zufall);
        // Creating the sphere
        sphere
                {
                <neu_x+2*(0.5-neu_radius)*rand(zufall)-(0.5-neu_radius),
neu_radius, neu_z+2*(0.5-neu_radius)*rand(zufall)-(0.5-neu_radius)>,
neu_radius
                texture
                        {
                        pigment
                                {
                                color rgb <1, 1, 0>
                                }
                        }
                }
        #declare i = i + 1;
#end


Post a reply to this message

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