根据颜色由三原色组成,根据其混成比例编写了此代码,实现了356种颜色的渐变过程;
//colort test;
const int red = 9;
const int green =10;
const int blue = 11;
void setup() {
{
pinMode(red, OUTPUT);
pinMode(green, OUTPUT);
pinMode(blue, OUTPUT);
}
}
void loop() {
//总共有8*8*4=256种颜色;
for(double r=0.125; r<=1.0; r+=0.125) //8
for(double g=0.125; g<=1.0; g+=0.125) //8
for(double b=0.25; b<=1.0; b+=0.25) //4
{
double k1=g/r; //比例系数;
double k2=b/r;
for(double number=1.0; number<=255.0; number+=1.0) //同比例增加;
{
double R=number;
double G=k1*R;
double B=k2*R;
if( R>254 ) //判断增加的值是否大于最大值255