色轮背后的数学是什么 [英] What is the math behind the Colour Wheel

查看:24
本文介绍了色轮背后的数学是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想制作一个有 12 个切片的馅饼,每个切片的颜色不同.

I want to create a pie with 12 slices, with each slice a different colour.

几乎每个色轮似乎都遵循相同的格式;例如:http://www.tigercolor.com/color-lab/color-theory/color-theory-intro.htm .

Pretty much every colour wheel seems to follow the same format; eg: http://www.tigercolor.com/color-lab/color-theory/color-theory-intro.htm .

但是有哪些算法可以生成颜色?RGB(theta) 背后的数学原理是什么?在这方面肯定有一些既定的科学,但谷歌没有给我任何线索.

But what algorithms are there for generating the colours? What is the math behind RGB(theta)? Surely there must be some established science on this, but Google is not giving me any clues.

推荐答案

查看 http://www.easyrgb.com 它具有许多颜色转换背后的算法.这是 RGB -> HSV 之一.

Have a look at http://www.easyrgb.com it has the algorithms behind many color conversions. Here's the RGB -> HSV one.

var_R = ( R / 255 )                     //RGB from 0 to 255
var_G = ( G / 255 )
var_B = ( B / 255 )

var_Min = min( var_R, var_G, var_B )    //Min. value of RGB
var_Max = max( var_R, var_G, var_B )    //Max. value of RGB
del_Max = var_Max - var_Min             //Delta RGB value 

V = var_Max

if ( del_Max == 0 )                     //This is a gray, no chroma...
{
   H = 0                                //HSV results from 0 to 1
   S = 0
}
else                                    //Chromatic data...
{
   S = del_Max / var_Max

   del_R = ( ( ( var_Max - var_R ) / 6 ) + ( del_Max / 2 ) ) / del_Max
   del_G = ( ( ( var_Max - var_G ) / 6 ) + ( del_Max / 2 ) ) / del_Max
   del_B = ( ( ( var_Max - var_B ) / 6 ) + ( del_Max / 2 ) ) / del_Max

   if      ( var_R == var_Max ) H = del_B - del_G
   else if ( var_G == var_Max ) H = ( 1 / 3 ) + del_R - del_B
   else if ( var_B == var_Max ) H = ( 2 / 3 ) + del_G - del_R

   if ( H < 0 ) H += 1
   if ( H > 1 ) H -= 1
}

这篇关于色轮背后的数学是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆