POV-Ray : Newsgroups : povray.beta-test : Colors.inc-macros incomplete Server Time
2 May 2024 02:21:21 EDT (-0400)
  Colors.inc-macros incomplete (Message 11 to 11 of 11)  
<<< Previous 10 Messages Goto Initial 10 Messages
From: Michael Andrews
Subject: Re: Colors.inc-macros incomplete
Date: 14 Sep 2001 13:19:39
Message: <3BA23DBD.52053F13@reading.ac.uk>
I've been doing some checks on the macros I posted - they are broken :-(

However ... I've had another go, done more extensive testing, and I
thing I have fixed versions here if they are wanted.

Bye for now,
	Mike Andrews.

// -- macros ---

#macro CRGB2HSV ( Pvec )
  #local vec = colour Pvec;
  #local V = max(vec.x, max(vec.y, vec.z));
  #if (V <= 0.0)
    #local R2H_col = colour rgbft <0, 0, 0, vec.filter, vec.transmit>;
  #else
    #local Vp = min(vec.x, min(vec.y, vec.z));
    #local S = (V-Vp)/V;
    #if (S <= 0.0)
      #local R2H_col = colour rgbft <0, 0, V, vec.filter, vec.transmit>;
    #else
      #local P = (V-vec)/(V-Vp);
      #if (P.x = 0)
        #if (P.y = 1)
          #local H = (5+P.z)/6;
        #else
          #local H = (1-P.y)/6;
        #end
      #end
      #if (P.y = 0)
        #if (P.z = 1)
          #local H = (1+P.x)/6;
        #else
          #local H = (3-P.z)/6;
        #end
      #end
      #if (P.z = 0)
        #if (P.x = 1)
          #local H = (3+P.y)/6;
        #else
          #local H = (5-P.x)/6;
        #end
      #end
     #local R2H_col = colour rgbft <H, S, V, vec.filter, vec.transmit>;
    #end
  #end
  <R2H_col.x,R2H_col.y,R2H_col.z,R2H_col.filter,R2H_col.transmit>
#end
      
#macro CHSV2RGB ( Pvec )
  #local vec = colour Pvec;
  #local H = mod((vec.x)*6, 6);
  #local H = ((H < 0)? H+6: H);
  #local P = floor(H);
  #local S = H - P;
  #local Y = (vec.y);
  #local Z = (vec.z);
  #local A = (1 - Y)*Z;
  #local B = (1 - (S*Y))*Z; 
  #local C = (1 - ((1-S)*Y))*Z;
  #switch (P)
    #case (0)
      #local H2R_col = colour rgbft <Z, C, A, vec.filter, vec.transmit>;
    #break
    #case (1)
      #local H2R_col = colour rgbft <B, Z, A, vec.filter, vec.transmit>;
    #break
    #case (2)
      #local H2R_col = colour rgbft <A, Z, C, vec.filter, vec.transmit>;
    #break
    #case (3)
      #local H2R_col = colour rgbft <A, B, Z, vec.filter, vec.transmit>;
    #break
    #case (4)
      #local H2R_col = colour rgbft <C, A, Z, vec.filter, vec.transmit>;
    #break
    #case (5)
      #local H2R_col = colour rgbft <Z, A, B, vec.filter, vec.transmit>;
    #break
  #end
  <H2R_col.x,H2R_col.y,H2R_col.z,H2R_col.filter,H2R_col.transmit>
#end

// -- end macros --

// -- test code --

#declare Xm = 30;
#declare Ym = 30;
#declare X = 0;
#while (X<=Xm)
   #declare Y = 0;
   #while (Y<=Ym)
      #declare Xv = (X/Xm);
      #declare Yv = (Y/Ym);
      sphere {
         <Xv-0.6,Yv-0.6,0>, 0.1
         pigment {color CHSV2RGB(<Xv,min(1,2*Yv),min(1,2-2*Yv)>)}
         finish {ambient 1 diffuse 0}
      }
      sphere {
         <Xv+0.6,Yv-0.6,0>, 0.1
         pigment {color
CHSV2RGB(CRGB2HSV(CHSV2RGB(<Xv,min(1,2*Yv),min(1,2-2*Yv)>)))}
         finish {ambient 1 diffuse 0}
      }
      sphere {
         <Xv-0.6,Yv+0.6,0>, 0.1
         pigment {color <Yv,Xv,1-Xv>}
         finish {ambient 1 diffuse 0}
      }
      sphere {
         <Xv+0.6,Yv+0.6,0>, 0.1
         pigment {color CHSV2RGB(CRGB2HSV(<Yv,Xv,1-Xv>))}
         finish {ambient 1 diffuse 0}
      }
      #declare Y=Y+1;
   #end
   #declare X=X+1;
#end
camera {translate <0.5,0.5,-2.5>}
background {color rgb 0.5}

// -- end test code --


Post a reply to this message

<<< Previous 10 Messages Goto Initial 10 Messages

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