极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10228|回复: 5

一个8*8的RGB点阵,找到了一个测试程序,都是英文,大家谁帮我看看,都是什么意思...

[复制链接]
发表于 2012-12-20 13:12:27 | 显示全部楼层 |阅读模式
#include <Colorduino.h>

typedef struct
{
  unsigned char r;
  unsigned char g;
  unsigned char b;
} ColorRGB;

//a color with 3 components: h, s and v
typedef struct
{
  unsigned char h;
  unsigned char s;
  unsigned char v;
} ColorHSV;

unsigned char plasma[ColorduinoScreenWidth][ColorduinoScreenHeight];
long paletteShift;


//Converts an HSV color to RGB color
void HSVtoRGB(void *vRGB, void *vHSV)
{
  float r, g, b, h, s, v; //this function works with floats between 0 and 1
  float f, p, q, t;
  int i;
  ColorRGB *colorRGB=(ColorRGB *)vRGB;
  ColorHSV *colorHSV=(ColorHSV *)vHSV;

  h = (float)(colorHSV->h / 256.0);
  s = (float)(colorHSV->s / 256.0);
  v = (float)(colorHSV->v / 256.0);

  //if saturation is 0, the color is a shade of grey
  if(s == 0.0) {
    b = v;
    g = b;
    r = g;
  }
  //if saturation > 0, more complex calculations are needed
  else
  {
    h *= 6.0; //to bring hue to a number between 0 and 6, better for the calculations
    i = (int)(floor(h)); //e.g. 2.7 becomes 2 and 3.01 becomes 3 or 4.9999 becomes 4
    f = h - i;//the fractional part of h

    p = (float)(v * (1.0 - s));
    q = (float)(v * (1.0 - (s * f)));
    t = (float)(v * (1.0 - (s * (1.0 - f))));

    switch(i)
    {
      case 0: r=v; g=t; b=p; break;
      case 1: r=q; g=v; b=p; break;
      case 2: r=p; g=v; b=t; break;
      case 3: r=p; g=q; b=v; break;
      case 4: r=t; g=p; b=v; break;
      case 5: r=v; g=p; b=q; break;
      default: r = g = b = 0; break;
    }
  }
  colorRGB->r = (int)(r * 255.0);
  colorRGB->g = (int)(g * 255.0);
  colorRGB->b = (int)(b * 255.0);
}

float
dist(float a, float b, float c, float d)
{
  return sqrt((c-a)*(c-a)+(d-b)*(d-b));
}


void
plasma_morph()
{
  unsigned char x,y;
  float value;
  ColorRGB colorRGB;
  ColorHSV colorHSV;

  for(y = 0; y < ColorduinoScreenHeight; y++)
    for(x = 0; x < ColorduinoScreenWidth; x++) {
      {
        value = sin(dist(x + paletteShift, y, 128.0, 128.0) / 8.0)
          + sin(dist(x, y, 64.0, 64.0) / 8.0)
          + sin(dist(x, y + paletteShift / 7, 192.0, 64) / 7.0)
          + sin(dist(x, y, 192.0, 100.0) / 8.0);
        colorHSV.h=(unsigned char)((value) * 128)&0xff;
        colorHSV.s=255;
        colorHSV.v=255;
        HSVtoRGB(&colorRGB, &colorHSV);
       
        Colorduino.SetPixel(x, y, colorRGB.r, colorRGB.g, colorRGB.b);
      }
  }
  paletteShift++;

  Colorduino.FlipPage(); // swap screen buffers to show it
}

/********************************************************
Name: ColorFill
Function: Fill the frame with a color
Parameter:R: the value of RED.   Range:RED 0~255
          G: the value of GREEN. Range:RED 0~255
          B: the value of BLUE.  Range:RED 0~255
********************************************************/
void ColorFill(unsigned char R,unsigned char G,unsigned char B)
{
  PixelRGB *p = Colorduino.GetPixel(0,0);
  for (unsigned char y=0;y<ColorduinoScreenWidth;y++) {
    for(unsigned char x=0;x<ColorduinoScreenHeight;x++) {
      p->r = R;
      p->g = G;
      p->b = B;
      p++;
    }
  }
  
  Colorduino.FlipPage();
}

void setup()
{
  Colorduino.Init(); // initialize the board
  
  // compensate for relative intensity differences in R/G/B brightness
  // array of 6-bit base values for RGB (0~63)
  // whiteBalVal[0]=red
  // whiteBalVal[1]=green
  // whiteBalVal[2]=blue
  unsigned char whiteBalVal[3] = {36,63,63}; // for LEDSEE 6x6cm round matrix
  Colorduino.SetWhiteBal(whiteBalVal);
  
  
  // start with morphing plasma, but allow going to color cycling if desired.
  paletteShift=128000;
  unsigned char bcolor;

  //generate the plasma once
  for(unsigned char y = 0; y < ColorduinoScreenHeight; y++)
    for(unsigned char x = 0; x < ColorduinoScreenWidth; x++)
    {
      //the plasma buffer is a sum of sines
      bcolor = (unsigned char)
      (
            128.0 + (128.0 * sin(x*8.0 / 16.0))
          + 128.0 + (128.0 * sin(y*8.0 / 16.0))
      ) / 2;
      plasma[x][y] = bcolor;
    }
   
// to adjust white balance you can uncomment this line
// and comment out the plasma_morph() in loop()
// and then experiment with whiteBalVal above
// ColorFill(255,255,255);
}

void loop()
{
  plasma_morph();
}
回复

使用道具 举报

发表于 2012-12-20 13:22:16 | 显示全部楼层
colorduino么,一直躺着还没玩
回复 支持 反对

使用道具 举报

 楼主| 发表于 2012-12-20 13:29:49 | 显示全部楼层
colorduino
回复 支持 反对

使用道具 举报

 楼主| 发表于 2012-12-20 13:34:06 | 显示全部楼层

就是这个板子

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复 支持 反对

使用道具 举报

发表于 2012-12-20 13:52:28 | 显示全部楼层
首先声明从学英语以来,只有初中得过一次72分,其他全没及格,闲来没事多个手,仅供参考
==========================================================


#include <Colorduino.h>

typedef struct
{
  unsigned char r;
  unsigned char g;
  unsigned char b;
} ColorRGB;

//a color with 3 components: h, s and v【hsv 三分色表示】
typedef struct
{
  unsigned char h;
  unsigned char s;
  unsigned char v;
} ColorHSV;

unsigned char plasma[ColorduinoScreenWidth][ColorduinoScreenHeight];
long paletteShift;


//Converts an HSV color to RGB color【将HSV格式转换为RGB】
void HSVtoRGB(void *vRGB, void *vHSV)
{
  float r, g, b, h, s, v; //this function works with floats between 0 and 1
  float f, p, q, t;
  int i;
  ColorRGB *colorRGB=(ColorRGB *)vRGB;
  ColorHSV *colorHSV=(ColorHSV *)vHSV;

  h = (float)(colorHSV->h / 256.0);
  s = (float)(colorHSV->s / 256.0);
  v = (float)(colorHSV->v / 256.0);

  //if saturation is 0, the color is a shade of grey 【如果色饱和度为0的话色彩为灰度】
if(s == 0.0) {
    b = v;
    g = b;
    r = g;
  }
  //if saturation > 0, more complex calculations are needed 【如果色饱和度大于0的话那就需要更复杂的计算】

  else
  {
    h *= 6.0; //to bring hue to a number between 0 and 6, better for the calculations【为了方便计算,色调定义成0~6】

    i = (int)(floor(h)); //e.g. 2.7 becomes 2 and 3.01 becomes 3 or 4.9999 becomes 4【举例2.7变为2,3.01变为3~~】

    f = h - i;//the fractional part of h【h的小数部分】


    p = (float)(v * (1.0 - s));
    q = (float)(v * (1.0 - (s * f)));
    t = (float)(v * (1.0 - (s * (1.0 - f))));

    switch(i)
    {
      case 0: r=v; g=t; b=p; break;
      case 1: r=q; g=v; b=p; break;
      case 2: r=p; g=v; b=t; break;
      case 3: r=p; g=q; b=v; break;
      case 4: r=t; g=p; b=v; break;
      case 5: r=v; g=p; b=q; break;
      default: r = g = b = 0; break;
    }
  }
  colorRGB->r = (int)(r * 255.0);
  colorRGB->g = (int)(g * 255.0);
  colorRGB->b = (int)(b * 255.0);
}

float
dist(float a, float b, float c, float d)
{
  return sqrt((c-a)*(c-a)+(d-b)*(d-b));
}


void
plasma_morph()
{
  unsigned char x,y;
  float value;
  ColorRGB colorRGB;
  ColorHSV colorHSV;

  for(y = 0; y < ColorduinoScreenHeight; y++)
    for(x = 0; x < ColorduinoScreenWidth; x++) {
      {
        value = sin(dist(x + paletteShift, y, 128.0, 128.0) / 8.0)
          + sin(dist(x, y, 64.0, 64.0) / 8.0)
          + sin(dist(x, y + paletteShift / 7, 192.0, 64) / 7.0)
          + sin(dist(x, y, 192.0, 100.0) / 8.0);
        colorHSV.h=(unsigned char)((value) * 128)&0xff;
        colorHSV.s=255;
        colorHSV.v=255;
        HSVtoRGB(&colorRGB, &colorHSV);
        
        Colorduino.SetPixel(x, y, colorRGB.r, colorRGB.g, colorRGB.b);
      }
  }
  paletteShift++;

  Colorduino.FlipPage(); // swap screen buffers to show it【置换显示缓冲以显示】

}

/********************************************************
Name: ColorFill
Function: Fill the frame with a color【填充色彩框架(样本)】

Parameter:R: the value of RED.   Range:RED 0~255【红】

          G: the value of GREEN. Range:RED 0~255【绿】

          B: the value of BLUE.  Range:RED 0~255【蓝】

********************************************************/
void ColorFill(unsigned char R,unsigned char G,unsigned char B)
{
  PixelRGB *p = Colorduino.GetPixel(0,0);
  for (unsigned char y=0;y<ColorduinoScreenWidth;y++) {
    for(unsigned char x=0;x<ColorduinoScreenHeight;x++) {
      p->r = R;
      p->g = G;
      p->b = B;
      p++;
    }
  }
  
  Colorduino.FlipPage();
}

void setup()
{
  Colorduino.Init(); // 初始化  
  // compensate for relative intensity differences in R/G/B brightness【补偿RGB亮度的相对强度】

  // array of 6-bit base values for RGB (0~63)【RGB 6位基值数组】

  // whiteBalVal[0]=red【红】

  // whiteBalVal[1]=green【绿】

  // whiteBalVal[2]=blue【蓝】

  unsigned char whiteBalVal[3] = {36,63,63}; // for LEDSEE 6x6cm round matrix【LEDSEE6x6点阵设定】

  Colorduino.SetWhiteBal(whiteBalVal);
  
  
  // start with morphing plasma, but allow going to color cycling if desired.【以离子变换方式开始,但是如果必要的话也允许色彩循环】

  paletteShift=128000;
  unsigned char bcolor;

  //generate the plasma once【生成一次】

  for(unsigned char y = 0; y < ColorduinoScreenHeight; y++)
    for(unsigned char x = 0; x < ColorduinoScreenWidth; x++)
    {
      //the plasma buffer is a sum of sines
      bcolor = (unsigned char)
      (
            128.0 + (128.0 * sin(x*8.0 / 16.0))
          + 128.0 + (128.0 * sin(y*8.0 / 16.0))
      ) / 2;
      plasma[x][y] = bcolor;
    }
   
// to adjust white balance you can uncomment this line【想调整白平衡的话你可以取消此行的注释标记,并且将loop()中的plasma_morph() 注释掉,然后测试白平衡】


// and comment out the plasma_morph() in loop()
// and then experiment with whiteBalVal above
// ColorFill(255,255,255);
}

void loop()
{
  plasma_morph();
}
回复 支持 反对

使用道具 举报

发表于 2013-1-7 20:45:45 | 显示全部楼层
mxx_xm 发表于 2012-12-20 13:52
首先声明从学英语以来,只有初中得过一次72分,其他全没及格,闲来没事多个手,仅供参考
================ ...

大神吗,英语不错。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-4-27 16:53 , Processed in 0.053085 second(s), 22 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表