Thema: Delphi Rgb <---> ryb

Einzelnen Beitrag anzeigen

WojTec

Registriert seit: 17. Mai 2007
480 Beiträge
 
Delphi XE6 Professional
 
#4

Re: Rgb <---> ryb

  Alt 15. Jun 2010, 18:53
Hmm, From RYB is not hard:

Code:
<script language="javascript1.1" type="text/javascript">

        function cubicInt(t, A, B){
          var weight = t*t*(3-2*t);
          return A + weight*(B-A);
          }

   function getR (iR, iY, iB) {
      var x0, x1, x2, x3, y0, y1;
      //red
      var x0 = cubicInt(iB, 1.0, 0.163);
      var x1 = cubicInt(iB, 1.0, 0.0);
      var x2 = cubicInt(iB, 1.0, 0.5);
      var x3 = cubicInt(iB, 1.0, 0.2);
      var y0 = cubicInt(iY, x0, x1);
      var y1 = cubicInt(iY, x2, x3);
      return Math.ceil (255 * cubicInt(iR, y0, y1));
        }

   function getG (iR, iY, iB) {
      var x0, x1, x2, x3, y0, y1;
      //green
      x0 = cubicInt(iB, 1.0, 0.373);
      x1 = cubicInt(iB, 1.0, 0.66);
      x2 = cubicInt(iB, 0.0, 0.0);
      x3 = cubicInt(iB, 0.5, 0.094);
      y0 = cubicInt(iY, x0, x1);
      y1 = cubicInt(iY, x2, x3);
      return Math.ceil (255 * cubicInt(iR, y0, y1));
         }

   function getB (iR, iY, iB) {
      var x0, x1, x2, x3, y0, y1;
      //blue
      x0 = cubicInt(iB, 1.0, 0.6);
      x1 = cubicInt(iB, 0.0, 0.2);
      x2 = cubicInt(iB, 0.0, 0.5);
      x3 = cubicInt(iB, 0.0, 0.0);
      y0 = cubicInt(iY, x0, x1);
      y1 = cubicInt(iY, x2, x3);
      return Math.ceil (255 * cubicInt(iR, y0, y1));
          }

   function RYB2RGB(){
      var R = document.all.r0.value;
      var Y = document.all.y0.value;
      var B = document.all.b0.value;
       
      
      if ( 
         isNaN( R ) || isNaN( Y ) || isNaN( B ) ||

         (R < 0 || R > 1) ||
         (Y < 0 || Y > 1) ||
         (B < 0 || B > 1)
         )
         {
         alert('Invalid RYB values');
         return;
      }
      //----------------------------
      var R1 = getR(R,Y,B) ;
      var G1 = getG(R,Y,B) ;
      var B1 = getB(R,Y,B) ;

      
      //----------------------------
      document.all.r1.innerText = R1;
      document.all.g1.innerText = G1;
      document.all.b1.innerText = B1;
      //-----------------------------


      document.getElementById("colorBox").style.backgroundColor="rgb("+R1+","+G1+","+B1+")";

   }

</script>
RYB elements should always be single in range 0..1?

What about from RGB?
  Mit Zitat antworten Zitat