原创 Labwindows/cvi8.5学习日志(33)----颜色梯度ColorRamps

2010-7-6 19:40 4005 8 8 分类: 软件与OS


//*********************************************************
// Labwindows/cvi8.5  颜色梯度 ColorRamps
// 改写自 Labwindows 自带的例程
// szlihongtao
// 2010-06-12
//*********************************************************
/*----------------------------------------------------------------------------*/
/*                                                                            */
/* Created for National Instruments - LabWindows/CVI 8.5 on 9/07/07           */
/*                                                                            */
/* FILE:    ColorRamps.c                                                      */
/*                                                                            */
/* PURPOSE: This example demonstrates how to programmatically get/set         */
/*          color ramps on various numeric controls. The program simulates    */
/*          an engine which generates heat as the faster it runs. The         */
/*          redline level and shutdown temperatures are adjustable. Changing  */
/*          those values causes the color ramps on multiple controls          */
/*          to update.                                                        */
/*                                                                            */
/*----------------------------------------------------------------------------*/


 



主要代码如下:


int CVICALLBACK ShutdownCB (int panel, int control, int event,
        void *callbackData, int eventData1, int eventData2)
{
    int maxTemp;
    ColorMapEntry thermColor[kThermEntries];


    switch (event)
    {
        case EVENT_VAL_CHANGED:
  {
            GetCtrlVal(panel, control, &maxTemp);
            /*  The Engine Temp ColorRamp uses interpolated colors to create smooth
                transitions between the colors. To create the solid black "shutdown"
                band that is not interpolated, add a VAL_BLACK entry at the same value
                we assigned the VAL_RED entry and then add another VAL_BLACK a little higher. */
            thermColor[0].dataValue.valInt = 0;
            thermColor[0].color = VAL_BLUE;
   
            thermColor[1].dataValue.valInt = maxTemp*0.4;
            thermColor[1].color = VAL_GREEN;
   
            thermColor[2].dataValue.valInt = maxTemp/2;
            thermColor[2].color = VAL_YELLOW;
   
            thermColor[3].dataValue.valInt = maxTemp;
            thermColor[3].color = VAL_RED;
   
            thermColor[4].dataValue.valInt = maxTemp;
            thermColor[4].color = VAL_BLACK;
   
            thermColor[5].dataValue.valInt = maxTemp+33;
            thermColor[5].color = VAL_BLACK;
   
            SetNumericColorRamp(panel, PANEL_NUMERICTHERM, thermColor, VAL_TRANSPARENT, kThermEntries, 0);
            break;
  }
    }
    return 0;
}


 

PARTNER CONTENT

文章评论0条评论)

登录后参与讨论
EE直播间
更多
我要评论
0
8
关闭 站长推荐上一条 /3 下一条