POV-Ray : Newsgroups : povray.general : Random Colour picker for spheres Server Time
16 Nov 2024 23:19:35 EST (-0500)
  Random Colour picker for spheres (Message 1 to 3 of 3)  
From: Zack Halbrecht
Subject: Random Colour picker for spheres
Date: 22 Feb 1970 23:46:19
Message: <01bd4014$038df340$0bab0680@zack>
Hey there everyone, i ve got what seemed to me like a pretty basic problem.
I have a while loop going and want it to draw a series of spheres.  How can
i
get it to pick a random color out of four which i determine.?
Im trying to use a switch statement like this but obviously not working.

#declare loop_iterator = 0
#while (loop_iterator <= (4 * PI))

#declare color1 = Orange
#declare color2 = Green
#declare color3 = Yellow
#declare color4 = Blue
#declare cx = Black
#declare cy = Black

object

#switch (s1)
        #case (0)
        cx = color1
        #end
        #case (1)
        cx = color2
        #end
        #case (2)
        cx = color3
        #end
        #case (3)
        cx = color4
#end        

#switch (s2)
        #case (0)
        cy = color1
        #end
        #case (1)
        cy = color2
        #end
        #case (2)
        cy = color3
        #end
        #case (3)
        cy = color4
#end        



  sphere { <sin(loop_iterator),loop_iterator,loop_iterator>, 1 pigment {
Sapphire_Agate } }
  sphere { <sin(loop_iterator) -5,loop_iterator,loop_iterator>,1 pigment {
color Yellow } }


#declare loop_iterator = loop_iterator + 2
#end

Can anyone help?

thanks in advance


-- 
Zack Halbrecht
Head Procrastinator
Rutgers University
zac### [at] edenrutgersedu


Post a reply to this message

From: Bill Bohan
Subject: Re: Random Colour picker for spheres
Date: 23 Feb 1998 03:40:01
Message: <34F135E0.CF9C0B02@technologist.com>
Zack,

Somewhere before your loop you need to seed a random generator:

#declare R1 = seed(0)

In your switches you need the rand function:

#switch (int(rand(R1)*3.999999 ))  // gives 0 to 3

Then you need to use your cx and cy values to set the colors for your spheres.
Also I noticed your syntax is not what POV is expecting. It needs to see lines
like:

#declare color1 = pigment{Orange}

and

       #case (0)
        cx = pigment{color1}

then you can set your colors like this:

  sphere { <sin(loop_iterator) -5,loop_iterator,loop_iterator>,1 pigment {
cx } }

I hope this helps.
Bill Bohan
http://www.dhc.net/~bilbohan
--
As many programmers as there are, that's how many ways there are to do it.


Post a reply to this message

From: Roland Mas
Subject: Re: Random Colour picker for spheres
Date: 23 Feb 1998 17:04:41
Message: <6csrpp$nb9$1@melchior.cuivre.fr.eu.org>
Zack Halbrecht (zac### [at] edenrutgersedu) wrote:
> Hey there everyone, i ve got what seemed to me like a pretty basic problem.
> I have a while loop going and want it to draw a series of spheres.  How can
> i
> get it to pick a random color out of four which i determine.?

I suggest using the rand() function (assuming you're using POV 3) combined
with a switch (too tired now to check the syntax in the docs, but sure it
lays there):

#declare loop_iterator = begin_iterator
#while (iterator < end_iterator)
  #declare A = rand()
  #declare B = rand()

  #switch (A)
    #range (0,0.25)
    #declare cx = colour Orange
    #break
    #range (0.25,0.5)
    #declare cx = colour Green
    #break
    #etc...
  #end
  #switch (B)
   #same here
  #end

  #sphere { ... texture { pigment { colour cx } } }
  #sphere { ... texture { pigment { colour cy } } }

  #declare iterator = iterator + increment
#end // #while ()

Happy ray-tracing,

B-o-b.
--

bob### [at] casimirrezelenstfr -- Linux, POV-Ray, LaTeX


Post a reply to this message

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