POV-Ray : Newsgroups : povray.general : Colors of the rainbow Server Time
30 Jul 2024 02:26:03 EDT (-0400)
  Colors of the rainbow (Message 1 to 7 of 7)  
From: ruy
Subject: Colors of the rainbow
Date: 12 Apr 2010 21:00:00
Message: <web.4bc3c1f5568629a3d9ac4bb10@news.povray.org>
Hello,

I'm trying to produce the colors of the rainbow inside a #while loop, but to no
avail so far. I need them to progress from red to violet, and I am using the
CHSV2RGB for the conversion, which I thought would make things easier. Still,
all I get is a constant red color in my blob.

Here is the code. The problem is in the blob with the loop (which produces an
ascending spiral):

#include "colors.inc"

camera{
 location < 0, 150, -1000 >
 look_at < 0, 20, 0.000 >
 angle 5.000
}

light_source{ <800,4000, 700> rgb 1 }

sphere {
  <0, 0, 0>, 1
  texture {
   pigment {
     gradient y
     color_map {
       [0.0 color rgb < 01.0, 01.0, 1.0 >]
       [0.0 color rgb < 01.0, 01.0, 1.0 >]
     }
   }
   finish { diffuse 0 ambient 1 }
  }
  hollow on
  no_shadow
  scale 30000
}

blob {
    threshold .0005

    #declare Cr = 0;
    #declare Mx = 2330;
    #declare Rd = 0.1;
    #declare Ap = 1;
    #declare As = 1;
    #declare Vl = 1;
    #while (Cr <= Mx)
        sphere { <0,0,0>, 1.3 ,1
                 translate <Cr*Ap*Rd*Rd,Cr*Vl*Rd*Rd*1.3, Cr*As*Rd*Rd>
                 rotate y*Cr*Vl
                 texture {
                         pigment{rgbft CHSV2RGB(<((Mx-Cr)/Mx), 1.0, 1.0>)}
                 }
        }
        #declare Cr = Cr + 1;
    #end
}
___________

My intention here is to produce an ascending spiral with seven turns; each turn
being of a color of the rainbow (or something close to that). The spiral ascends
alright, but the colors don't vary at all.

There's very little documentation on CHSV2RGB, and I found no examples of it in
action, so any help will be greatly appreciated.

Ruy (an extremely absent POVer since 1994, version 2.2)


Post a reply to this message

From: Alain
Subject: Re: Colors of the rainbow
Date: 12 Apr 2010 22:21:10
Message: <4bc3d516$1@news.povray.org>

> Hello,
>
> I'm trying to produce the colors of the rainbow inside a #while loop, but to no
> avail so far. I need them to progress from red to violet, and I am using the
> CHSV2RGB for the conversion, which I thought would make things easier. Still,
> all I get is a constant red color in my blob.
>
>
> Ruy (an extremely absent POVer since 1994, version 2.2)
>
>

The hue is given in degree. In your sample, it goes from 0 degree to 1 
degree, giving an almost imperceptible change in coloration.

Change your code to:
#local Hue = (Mx-Cr)/Mx*360;
// Scale to a full circle on the colour wheel
// Adjust if you want to use a smaller or larger range
texture {
          pigment{rgb CHSV2RGB(<Hue, 1.0, 1.0>)}
         }

OR change your pigment to:
pigment{rgb CHSV2RGB(<((Mx-Cr)/Mx)*360, 1.0, 1.0>)}



Alain


Post a reply to this message

From: ruy
Subject: Re: Colors of the rainbow
Date: 13 Apr 2010 04:35:01
Message: <web.4bc42c08db1f0f0260ff6bf40@news.povray.org>
Ah, so Hue varies from 0 to 360 degrees while Saturation and Value vary from 0
to 1. That's a very interesting piece of information. Exactly what I needed to
hear, Alain, merci!

It worked perfectly.

Ruy

Alain <aze### [at] qwertyorg> wrote:
>
> Change your code to:
> #local Hue = (Mx-Cr)/Mx*360;
> // Scale to a full circle on the colour wheel
> // Adjust if you want to use a smaller or larger range
> texture {
>           pigment{rgb CHSV2RGB(<Hue, 1.0, 1.0>)}
>          }
>
> OR change your pigment to:
> pigment{rgb CHSV2RGB(<((Mx-Cr)/Mx)*360, 1.0, 1.0>)}
>
>
>
> Alain


Post a reply to this message

From: Alain
Subject: Re: Colors of the rainbow
Date: 13 Apr 2010 11:07:19
Message: <4bc488a7$1@news.povray.org>

> Ah, so Hue varies from 0 to 360 degrees while Saturation and Value vary from 0
> to 1. That's a very interesting piece of information. Exactly what I needed to
> hear, Alain, merci!
>
> It worked perfectly.
>
> Ruy
>
> Alain<aze### [at] qwertyorg>  wrote:
>>
>> Change your code to:
>> #local Hue = (Mx-Cr)/Mx*360;
>> // Scale to a full circle on the colour wheel
>> // Adjust if you want to use a smaller or larger range
>> texture {
>>            pigment{rgb CHSV2RGB(<Hue, 1.0, 1.0>)}
>>           }
>>
>> OR change your pigment to:
>> pigment{rgb CHSV2RGB(<((Mx-Cr)/Mx)*360, 1.0, 1.0>)}
>>
>>
>>
>> Alain
>
>
>
>

To find that, you need to look inside colors.inc.
CHSV2RGB internaly calls CH2RGB.

CH2RGB is defined as:
#macro CH2RGB (H)
    #local H = mod(H, 360);
    #local H = (H < 0 ? H+360 : H);
    #switch (H)
       #range (0, 120)
          #local R = (120-  H) / 60;
          #local G = (  H-  0) / 60;
          #local B = 0;
       #break
       #range (120, 240)
          #local R = 0;
          #local G = (240-  H) / 60;
          #local B = (  H-120) / 60;
       #break
       #range (240, 360)
          #local R = (  H-240) / 60;
          #local G = 0;
          #local B = (360-  H) / 60;
       #break
    #end
    <min(R,1), min(G,1), min(B,1)>
#end

When you look at that code, it becomes obvious that you are using 
degrees. CHSL2RGB() also use degrees.
It should be added to the documentation.


Alain


Post a reply to this message

From: Jim Holsenback
Subject: Re: Colors of the rainbow
Date: 13 Apr 2010 13:31:37
Message: <4bc4aa79$1@news.povray.org>
Alain wrote:

> It should be added to the documentation.
>

Done ...
http://wiki.povray.org/content/Documentation:Reference_Section_7#Color_macros

Jim


Post a reply to this message

From: Doctor John
Subject: Re: Colors of the rainbow
Date: 14 Apr 2010 06:10:52
Message: <4bc594ac@news.povray.org>
ruy wrote:
> 
> Ruy (an extremely absent POVer since 1994, version 2.2)
> 

Definitely OOC but welcome back.
You have been assimilated, resistance was futile :-)

John
-- 
Cogito sum,|| wbu### [at] tznvypbz (rot'ed) || GPG Key Fingerprint:
ergo sum,  ||   These opinions are mine alone,   || 0D9BCF4CF1B71CA2F5F7
cogito     ||     others can find their own      || BFBBCBC34EDEAEFCE453


Post a reply to this message

From: ruy
Subject: Re: Colors of the rainbow
Date: 14 Apr 2010 14:00:00
Message: <web.4bc60265db1f0f021ad2eb90@news.povray.org>
> > It should be added to the documentation.
> >
>
> Done ...
> http://wiki.povray.org/content/Documentation:Reference_Section_7#Color_macros
>
> Jim

Excellent, thank you very much!

> > Ruy (an extremely absent POVer since 1994, version 2.2)
> >
>
> Definitely OOC but welcome back.
> You have been assimilated, resistance was futile :-)
>
> John

Thanks! It's good to be back, even if just for a short while. :D

Ruy


Post a reply to this message

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