Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Multimedia (https://www.delphipraxis.net/16-multimedia/)
-   -   Delphi Rgb <---> ryb (https://www.delphipraxis.net/152223-rgb-ryb.html)

WojTec 15. Jun 2010 16:06


Rgb <---> ryb
 
I found new (but historical) colors set - RYB. Do you know how to make convertion RGB <---> RYB (I not found any informations about it)?

mkinzler 15. Jun 2010 16:08

AW: Rgb <---> ryb
 
It ain't that easy. Because you have to calc Yellow from the other color channels

tkone 15. Jun 2010 16:49

AW: Rgb <---> ryb
 
try looking here

http://www.paintassistant.com/rybrgb.html

WojTec 15. Jun 2010 18:53

Re: Rgb <---> ryb
 
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?

tkone 16. Jun 2010 11:06

AW: Rgb <---> ryb
 
converting ryb and rgb is only a mathematical construct. the way to convert is by a color wheel or the cubic interpolation method. you need to have a look at what the javascript does, and why.
if you understood, how to transform ryb to rgb you can possibly rearange the term for rgb to ryb.

the 0..1 is because only the propotions count in ryb/cmy/cmyk (historical because of mixing paint)
the rgb (0..255) is only because they are used for computerlanguage (hex) 00 to FF

WojTec 4. Jan 2012 15:58

Re: Rgb <---> ryb
 
I don't know how to reverse it back. I searched over the net, and don't found any information (only wheel) about this model and conversions. Please F1.


Alle Zeitangaben in WEZ +1. Es ist jetzt 17:38 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz