Beispiel #1
0
void RenderBuffer::SetState(int period, bool ResetState, const std::string& model_name)
{
    if (ResetState)
    {
        needToInit = true;
    }
    curPeriod = period;
    cur_model = model_name;
    curPeriod = period;
    palette.UpdateForProgress(GetEffectTimeIntervalPosition());
}
void RgbEffects::RenderSingleStrandSkips(int Skips_BandSize, int Skips_SkipSize, int Skips_StartPos, const wxString & Skips_Direction)
{
    int x = Skips_StartPos - 1;
    xlColour color, black(0,0,0);
    int second = 0;
    int max = BufferWi;
    int direction = mapDirection(Skips_Direction);
    if (direction > 1) {
        max /= 2;
    }



    size_t colorcnt = GetColorCount();
    if (fitToTime) {
        int position = (GetEffectTimeIntervalPosition() * speed);
        x += position * Skips_BandSize;
    } else if (speed > 1) {
        int cur = state / 10;
        x += cur * Skips_BandSize;
    }
    while (x > max) {
        x -= (Skips_BandSize +  Skips_SkipSize) * colorcnt;
    }

    int firstX = x;
    int colorIdx = 0;

    while (x < max) {
        palette.GetColor(colorIdx, color);
        colorIdx++;
        if (colorIdx >= colorcnt) {
            colorIdx = 0;
        }
        for (int cnt = 0; cnt < Skips_BandSize && x < max; cnt++) {
            int mappedX = mapX(x, max, direction, second);
            if (mappedX >= 0 && mappedX < BufferWi) {
                for (int y = 0; y < BufferHt; y++) {
                    SetPixel(mappedX, y, color);
                }
            }
            if (second >= 0 && second < BufferWi) {
                for (int y = 0; y < BufferHt; y++) {
                    SetPixel(second, y, color);
                }
            }
            x++;
        }
        x += Skips_SkipSize;
    }
    colorIdx = GetColorCount() - 1;
    x = firstX - 1;
    while (x >= 0) {
        x -= Skips_SkipSize;

        palette.GetColor(colorIdx, color);
        colorIdx--;
        if (colorIdx < 0) {
            colorIdx = GetColorCount() - 1;
        }
        for (int cnt = 0; cnt < Skips_BandSize && x >= 0; cnt++) {
            int mappedX = mapX(x, max, direction, second);
            if (mappedX >= 0 && mappedX < BufferWi) {
                for (int y = 0; y < BufferHt; y++) {
                    SetPixel(mappedX, y, color);
                }
            }
            if (second >= 0 && second < BufferWi) {
                for (int y = 0; y < BufferHt; y++) {
                    SetPixel(second, y, color);
                }
            }
            x--;
        }
    }
}
void RgbEffects::RenderSingleStrandChase(int ColorScheme,int Number_Chases, int Color_Mix1,int Chase_Spacing1,
                                    int Chase_Type1,bool Chase_Fade3d1,bool Chase_Group_All)
{

    int x,x1,x0,y,i,ColorIdx,chases,width,slow_state;
    int x2=0;
    int x_2=0;
    int x2_mod=0;
    int color_index,x1_mod,mod_ChaseDirection;
    int MaxNodes,xt,Dual_Chases,All_Arches=0;
    int start1,start2,start1_mid,xend,start1_group;
    float dx;

    bool R_TO_L1;

    //srand (time(NULL)); // for strobe effect, make lights be random
    srand(1); // else always have the same random numbers for each frame (state)
    wxImage::HSVValue hsv; //   we will define an hsv color model. The RGB colot model would have been "wxColour color;"

    size_t colorcnt=GetColorCount(); // global now set to how many colors have been picked
    y=BufferHt;
    i=0;
    int state_width = state/BufferWi;
    int state_col = (state_width*BufferWi) + state%10;
    int state_ht = state_width%BufferHt; // 0 .. (BufferHt-1)

    int curEffStartPer, curEffEndPer,  nextEffTimePeriod;

    GetEffectPeriods( curEffStartPer, nextEffTimePeriod, curEffEndPer);
    double rtval = GetEffectTimeIntervalPosition();


    if(Chase_Spacing1<1) Chase_Spacing1=1;
    int ymax=BufferHt;
    if(Chase_Group_All || Chase_Type1==3) MaxNodes= BufferWi*BufferHt;
    else MaxNodes=BufferWi;

    int MaxChase=MaxNodes*(Color_Mix1/100.0);
    if(MaxChase<1) MaxChase=1;
    
    int nodes_per_color = int(MaxChase/colorcnt);
    if(nodes_per_color<1)  nodes_per_color=1;    //  fill chase buffer

    hsv.value=0.0;
    hsv.saturation=1.0;
    hsv.hue=0.0;


    int AutoReverse=0;
    start1 = state % BufferWi;
    start1 = (int)(state/2) % MaxNodes; // divide by 4 slows down chase
    start1_group = (int)(state/2) / MaxNodes; // divide by 4 slows down chase
    start2 = MaxNodes-start1;
    start1_mid = MaxNodes/2;
    if(state==0) ChaseDirection=0; // initialize it once at the beggining of this sequence.
    switch (Chase_Type1)
    {
    case 0: // "Normal. L-R"
        R_TO_L1=0;
        break;

    case 1: // "Normal. R-L"
        R_TO_L1=1;
        break;

    case 2: // "Auto reverse"
        AutoReverse=1;
        break;

    case 3: // "Bounce"
        Dual_Chases=1;
        break;
    case 4: // "Pacman"

        break;
    }
    //  we have a global variablal, ChaseDirection, which indicates which way we are moving.


    int FIT_TO_TIME=(fitToTime);
    int numberFrames=0;
    if(fitToTime) // is "Fit to Time" checked?
    {
        numberFrames=nextEffTimePeriod-nextEffTimePeriod;
        //   GetEffectPeriods( nextEffTimePeriod, nextEffTimePeriod, curEffEndPer);
//    double rtval = GetEffectTimeIntervalPosition();
//  rtval 0 to 1.0. This indicates how far we are through this row on the grid.
//      0.0 we are just starting the effect on this row
//      1.0 we have come t the end of time for this effect
    }
    hsv.value=1.0;
    hsv.saturation=1.0;
    hsv.hue=0.0; // RED
    if(Chase_Group_All)
    {
        width=MaxNodes;
    }
    else
    {
        width=BufferWi;
    }
    if(Number_Chases<1) Number_Chases=1;
    if(ColorScheme<0) ColorScheme=0;
    dx = width/Number_Chases;
    if(dx<1) dx=1.0;

    for(chases=1; chases<=Number_Chases; chases++)
    {
        if(fitToTime)
            slow_state = width * rtval;
        else
            slow_state = (state/4)%width;

        //   if(R_TO_L1)
        mod_ChaseDirection=ChaseDirection%2;    // 0= R-L, 1=L-R
        if(AutoReverse) // if we are bouncing back and forth
        {
            if(mod_ChaseDirection==1) // which direction should we be going
                x1=int(0.5 + (chases-1)*dx)+slow_state; // L-R
            else
                x1=int(0.5 + width-((chases-1)*dx)-slow_state); // R-L
        }
        else // we are just doing L-R or R-L
        {
            if(R_TO_L1) // 1 = L-R, 0=R-L
                x1=int(0.5 + (chases-1)*dx)+slow_state; // L-R
            else
                x1=int(0.5 + width-((chases-1)*dx)-slow_state); // R-L
        }

        if(x1<=0)
        {
            x1+=width;
            ChaseDirection++;

        }
        else if(x1>=width)
        {
            x1-=width;
            ChaseDirection++;
        }
        if(x1<0) x1=0;
        x=x1%BufferWi;
        if(Chase_Group_All)
        {
            y = (x1%MaxNodes)/BufferWi;
            draw_chase(x,y,hsv,ColorScheme,Number_Chases,width,R_TO_L1,Color_Mix1,Chase_Fade3d1,ChaseDirection); // Turn pixel on
        }
        else
        {
            // NOT A GROUP
            for(y=0; y<BufferHt; y++)
            {
                draw_chase(x,y,hsv,ColorScheme,Number_Chases,width,R_TO_L1,Color_Mix1,Chase_Fade3d1,ChaseDirection); // Turn pixel on
                if(Dual_Chases)
                {
                    if(R_TO_L1) // 1 = L-R, 0=R-L
                        x2=width-x-1;
                    else
                        x2=width-x-1;
                    draw_chase(x2,y,hsv,ColorScheme,Number_Chases,width,R_TO_L1,Color_Mix1,Chase_Fade3d1,ChaseDirection); //
                }
            }

        }
    }
}
Beispiel #4
0
void RgbEffects::RenderSpirals(int PaletteRepeat, int Direction, int Rotation, int Thickness,
                               bool Blend, bool Show3D, bool grow, bool shrink)
{
    int strand_base,strand,thick,x,y,ColorIdx;
    size_t colorcnt=GetColorCount();
    int SpiralCount=colorcnt * PaletteRepeat;
    int deltaStrands=BufferWi / SpiralCount;
    int SpiralThickness=(deltaStrands * Thickness / 100) + 1;
    int spiralGap = deltaStrands - SpiralThickness;
    long SpiralState;
    long ThicknessState = state/10;
    wxImage::HSVValue hsv;
    wxColour color;


    if (fitToTime)
    {
        double position = GetEffectTimeIntervalPosition();
        if (grow&&shrink)
        {
            ThicknessState = position <= 0.5?spiralGap*(position*2):spiralGap*((1-position) * 2);
        }
        else if (grow)
        {
                ThicknessState = spiralGap *position;
        }
        else if (shrink)
        {
            ThicknessState = spiralGap * (1-position);
        }
        SpiralState = position*BufferWi*10*Direction;
    }
    else
    {
        SpiralState=state*Direction;
    }

    spiralGap += (spiralGap==0);
    if (grow && (!shrink || ((ThicknessState/spiralGap)%2)==0))
    {
        SpiralThickness += ThicknessState%(spiralGap);
    }
    else if (shrink && (!grow || ((ThicknessState/spiralGap)%2)==1))
    {
        SpiralThickness +=spiralGap-ThicknessState%(spiralGap);
    }

    for(int ns=0; ns < SpiralCount; ns++)
    {
        strand_base=ns * deltaStrands;
        ColorIdx=ns % colorcnt;
        palette.GetColor(ColorIdx,color);
        for(thick=0; thick < SpiralThickness; thick++)
        {
            strand = (strand_base + thick) % BufferWi;
            for(y=0; y < BufferHt; y++)
            {
                x=(strand + SpiralState/10 + y*Rotation/BufferHt) % BufferWi;
                if (x < 0) x += BufferWi;
                if (Blend)
                {
                    GetMultiColorBlend(double(BufferHt-y-1)/double(BufferHt), false, color);
                }
                if (Show3D)
                {
                    Color2HSV(color,hsv);
                    if (Rotation < 0)
                    {
                        hsv.value*=double(thick+1)/SpiralThickness;
                    }
                    else
                    {
                        hsv.value*=double(SpiralThickness-thick)/SpiralThickness;
                    }
                    SetPixel(x,y,hsv);
                }
                else
                {
                    SetPixel(x,y,color);
                }
            }
        }
    }
}
Beispiel #5
0
void RgbEffects::RenderRipple(int Object_To_Draw, int Movement)
{

    int x,y,i,i7,ColorIdx;
    int xc,yc;

#if 0
    if(step<1) step=1;
    if(Use_All_Colors) srand (time(NULL)); // for Use_All_Colors effect, make lights be random
    else srand(1); // else always have the same random numbers for each frame (state)
#endif

    wxImage::HSVValue hsv; //   we will define an hsv color model. The RGB colot model would have been "wxColour color;"
    srand (time(NULL));
    size_t colorcnt=GetColorCount();

    i=0;
    double position = GetEffectTimeIntervalPosition(); // how far are we into the row> value is 0.0 to 1.0
    float rx;
    xc = BufferWi/2;
    yc=BufferHt/2;
    int on_off=0;

    int slices=200;
    int istate=state/slices; // istate will be a counter every slices units of state. each istate is a square wave
    int imod=(state/(slices/10))%10; // divide this square
    int icolor=istate%colorcnt;
    wxString TimeNow =wxNow();
    rx=(state%slices)/(slices*1.0);

    int x1 = xc - (xc*rx);
    int x2 = xc + (xc*rx);
    int y1 = yc - (yc*rx);
    int y2 = yc + (yc*rx);
    enum {Square, Circle, Triangle} shape = Circle;
    double radius;
    //  debug(10, "%s:%6d istate=%4d imod=%4d icolor=%1d", (const char*)TimeNow,state,istate,imod,icolor);
    ColorIdx=rand()% colorcnt; // Select random numbers from 0 up to number of colors the user has checked. 0-5 if 6 boxes checked
    palette.GetHSV(ColorIdx, hsv); // Now go and get the hsv value for this ColorIdx
    int explode;
    switch (Object_To_Draw)
    {

    case RENDER_RIPPLE_SQUARE:
        explode=1;
        if(Movement==MOVEMENT_EXPLODE)
        {
            // This is the object expanding out, or explode looikng
            int x1 = xc - (xc*rx);
            int x2 = xc + (xc*rx);
            int y1 = yc - (yc*rx);
            int y2 = yc + (yc*rx);
            for(y=y1; y<=y2; y++)
            {
                SetP(x1,y,hsv); // Turn pixel
                SetP(x2,y,hsv); // Turn pixel
            }
            for(x=x1; x<=x2; x++)
            {
                SetP(x,y1,hsv); // Turn pixel
                SetP(x,y2,hsv); // Turn pixel
            }

            hsv.value = (hsv.value /3)*2;
            for(y=y1; y<=y2; y++)
            {
                SetP(x1+1,y,hsv); // Turn pixel
                SetP(x2-1,y,hsv); // Turn pixel
            }
            for(x=x1; x<=x2; x++)
            {
                SetP(x,y1+1,hsv); // Turn pixel
                SetP(x,y2-1,hsv); // Turn pixel
            }

            hsv.value = hsv.value /3;
            for(y=y1; y<=y2; y++)
            {
                SetP(x1+2,y,hsv); // Turn pixel
                SetP(x2-2,y,hsv); // Turn pixel
            }
            for(x=x1; x<=x2; x++)
            {
                SetP(x,y1+2,hsv); // Turn pixel
                SetP(x,y2-2,hsv); // Turn pixel
            }

        }
        else if(Movement==MOVEMENT_IMPLODE)
        {
            int x1 = (xc*rx);
            int x2 = BufferWi - (xc*rx);
            int y1 =  (yc*rx);
            int y2 = BufferHt - (yc*rx);
            for(y=y2; y>=y1; y--)
            {
                SetP(x1,y,hsv); // Turn pixel
                SetP(x2,y,hsv); // Turn pixel
            }
            for(x=x2; x>=x1; x--)
            {
                SetP(x,y1,hsv); // Turn pixel
                SetP(x,y2,hsv); // Turn pixel
            }
        }
        break;
    case RENDER_RIPPLE_CIRCLE:
        if(Movement==MOVEMENT_IMPLODE)
            radius = xc-(xc*rx);
        else
            radius = (xc*rx);


        Drawcircle( xc, yc, radius, hsv);
        radius=radius/2;
        Drawcircle( xc, yc, radius, hsv);
        radius=radius/2;
        Drawcircle( xc, yc, radius, hsv);
        radius=radius/2;
        Drawcircle( xc, yc, radius, hsv);
        break;
    case RENDER_RIPPLE_TRIANGLE:
        break;
    }
}
Beispiel #6
0
// edge: 0=left, 1=center, 2=right
// effect: 0=open, 1=close, 2=open then close, 3=close then open
void RgbEffects::RenderCurtain(int edge, int effect, int swag, bool repeat)
{
    double a;
    wxImage::HSVValue hsv;
    wxArrayInt SwagArray;
    int CurtainDir,xlimit,middle, ylimit;
    int swaglen=BufferHt > 1 ? swag * BufferWi / 40 : 0;
    double position = GetEffectTimeIntervalPosition();

    if (swaglen > 0) {
        a=double(BufferHt - 1) / (swaglen * swaglen);
        for (int x=0; x<swaglen; x++) {
            SwagArray.Add(int(a*x*x));
        }
    }
    if (effect < E_CURTAIN_OPEN_CLOSE) {
        if(fitToTime)
        {
            xlimit=position * BufferWi;
            ylimit=position * BufferHt;
        }
        else
        {
            xlimit=repeat || state < 200 ? (state % 200) * BufferWi / 199 : BufferWi;
            ylimit=repeat || state < 200 ? (state % 200) * BufferHt / 199 : BufferHt;
        }
    } else {
        if(fitToTime)
        {
            xlimit= position <= .5 ? position * 2 * BufferWi: (position -.5) * 2 * BufferWi ;
            ylimit= position <= .5 ? position * 2 * BufferHt: (position -.5) * 2 * BufferHt ;
        }
        else
        {
            xlimit=repeat || state < 400 ? (state % 200) * BufferWi / 199 : 0;
            ylimit=repeat || state < 400 ? (state % 200) * BufferHt / 199 : 0;
        }
    }
    if (state == 0 || effect < E_CURTAIN_OPEN_CLOSE) {
        CurtainDir=effect % 2;
    } else if (xlimit < LastCurtainLimit) {
        CurtainDir=1-LastCurtainDir;
    } else {
        CurtainDir=LastCurtainDir;
    }
    LastCurtainDir=CurtainDir;
    LastCurtainLimit=xlimit;
    if (CurtainDir==0)
    {
        xlimit=BufferWi-xlimit-1;
        ylimit=BufferHt-ylimit-1;
    }
    switch (edge) {
        case 0:
            // left
            DrawCurtain(true,xlimit,SwagArray);
            break;
        case 1:
            // center
            middle=(xlimit+1)/2;
            DrawCurtain(true,middle,SwagArray);
            DrawCurtain(false,middle,SwagArray);
            break;
        case 2:
            // right
            DrawCurtain(false,xlimit,SwagArray);
            break;
        case 3:
            DrawCurtainVertical(true, ylimit, SwagArray);
            break;
        case 4:
            middle=(ylimit+1)/2;
            DrawCurtainVertical(true, middle, SwagArray);
            DrawCurtainVertical(false, middle, SwagArray);
            break;
        case 5:
            DrawCurtainVertical(false, ylimit, SwagArray);
            break;
    }
}