【VC开源代码栏目提醒】:网学会员在VC开源代码频道为大家收集整理了CPlasmaRoutine.cpp提供大家参考,希望对大家有所帮助!
// PlasmaRoutine.cpp: implementation of the CPlasmaRoutine class.
//
//////////////////////////////////////////////////////////////////////
#include "CPlasmaRoutine.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
#include <math.h>
CPlasmaRoutine::CPlasmaRoutine()
{
m_iHeight = 0;
m_iWidth = 0;
m_pPlasmaBits = NULL;
m_iAlpha = 255;
m_a1=0;
m_a2=0;
m_a3=0;
m_a4=0;
m_b1=0;
m_b2=0;
m_b3=0;
m_b4=0;
m_iModifier1=1;
m_iModifier2=2;
m_iModifier3=1;
m_iModifier4=2;
m_iXModifier1 = -1;
m_iXModifier2 = 3;
m_iYModifier1 = 1;
m_iYModifier2 = -2;
// Set up our defalt plasma colors
m_PlasmaColors[0]=RGB(0,0,0);// From black
m_PlasmaColors[1]=RGB(0,0,255);// To Blue
m_PlasmaColors[2]=RGB(0,0,255);// From Blue
m_PlasmaColors[3]=RGB(0,255,0);// To Green
m_PlasmaColors[4]=RGB(0,255,0);// From Green
m_PlasmaColors[5]=RGB(0,255,255);// To Cyan
m_PlasmaColors[6]=RGB(0,255,255);// Cyan
m_PlasmaColors[7]=RGB(0,255,255);
m_PlasmaColors[8]=RGB(0,255,255);// Cyan
m_PlasmaColors[9]=RGB(0,255,255);
m_PlasmaColors[10]=RGB(0,255,255);// From White
m_PlasmaColors[11]=RGB(0,255,0); // To dark green
m_PlasmaColors[12]=RGB(0,255,0);// From Dark Blue
m_PlasmaColors[13]=RGB(0,0,255);// To dark green
m_PlasmaColors[14]=RGB(0,0,255);// From Dark Blue
m_PlasmaColors[15]=RGB(0,0,0);// To Black
}
CPlasmaRoutine::~CPlasmaRoutine()
{
if(m_pPlasmaBits != NULL)
delete [] m_pPlasmaBits;
m_pPlasmaBits = NULL;
}
void CPlasmaRoutine::InitCostBLTable()
{
for(int t=0;t<256;t++)
m_icostbl[t] = (int)( 30 * cos(t * (3.14159/64) ) );
}
inline void CPlasmaRoutine::SetRGB(int iIndex,int R,int G,int B)
{
COLORREF color = RGB(R+50,G+50,B+50);
m_pPalletteBuffer[iIndex] = color;
}
void CPlasmaRoutine::InitPallette()
{
// Create a gradient between all the colors we have for our plasma
CreateGradient(m_PlasmaColors[0],m_PlasmaColors[1],32,&m_pPalletteBuffer[0]); // From black to Blue
CreateGradient(m_PlasmaColors[2],m_PlasmaColors[3],32,&m_pPalletteBuffer[32]); // From Green to Blue
CreateGradient(m_PlasmaColors[4],m_PlasmaColors[5],32,&m_pPalletteBuffer[64]); // From Green to White
CreateGradient(m_PlasmaColors[6],m_PlasmaColors[6],32,&m_pPalletteBuffer[96]);// From Cyan to Cyan
CreateGradient(m_PlasmaColors[8],m_PlasmaColors[9],32,&m_pPalletteBuffer[128]);// Cyan To Cyan
CreateGradient(m_PlasmaColors[10],m_PlasmaColors[11],32,&m_pPalletteBuffer[160]);// While to dark Green
CreateGradient(m_PlasmaColors[12],m_PlasmaColors[13],32,&m_pPalletteBuffer[192]);// Dark Blue to dark green
CreateGradient(m_PlasmaColors[14],m_PlasmaColors[15],32,&m_pPalletteBuffer[224]);// Dark Blue to black
}
inline void CPlasmaRoutine::CreateGradient(COLORREF clrStart,COLORREF clrEnd,long lSteps,COLORREF* pBuffer)
{
// I created this routine to make real smooth gradients...
// It may not be real optimized, but it works....and that is what matters to me right now...
int r, g, b; // First distance, then starting value
int rTotal,gTotal,bTotal;
int roffset,goffset,boffset;
int scalerR;
int scalerG;
int scalerB;
roffset = goffset = boffset = 0;
scalerR = scalerG = scalerB = 0;
// Get the color differences and scalers
rTotal = GetRValue(clrEnd) - GetRValue(clrStart);
if(rTotal < 0)
scalerR = -1;
else if(rTotal > 0)
scalerR = 1;
gTotal = GetGValue(clrEnd) - GetGValue(clrStart);
if(gTotal