void RgbEffects::RenderSnowflakes(int Count, int SnowflakeType) { int i,n,x,y0,y,check,delta_y; wxColour color1,color2; if (state == 0 || Count != LastSnowflakeCount || SnowflakeType != LastSnowflakeType) { // initialize LastSnowflakeCount=Count; LastSnowflakeType=SnowflakeType; palette.GetColor(0,color1); palette.GetColor(1,color2); ClearTempBuf(); // place Count snowflakes for (n=0; n < Count; n++) { delta_y=BufferHt/4; y0=(n % 4)*delta_y; if (y0+delta_y > BufferHt) delta_y = BufferHt-y0; // find unused space for (check=0; check < 20; check++) { x=rand() % BufferWi; y=y0 + (rand() % delta_y); if (GetTempPixelRGB(x,y) == 0) break; } // draw flake, SnowflakeType=0 is random type switch (SnowflakeType == 0 ? rand() % 5 : SnowflakeType-1) { case 0: // single node SetTempPixel(x,y,color1); break; case 1: // 5 nodes if (x < 1) x+=1; if (y < 1) y+=1; if (x > BufferWi-2) x-=1; if (y > BufferHt-2) y-=1; SetTempPixel(x,y,color1); SetTempPixel(x-1,y,color2); SetTempPixel(x+1,y,color2); SetTempPixel(x,y-1,color2); SetTempPixel(x,y+1,color2); break; case 2: // 3 nodes if (x < 1) x+=1; if (y < 1) y+=1; if (x > BufferWi-2) x-=1; if (y > BufferHt-2) y-=1; SetTempPixel(x,y,color1); if (rand() % 100 > 50) // % 2 was not so random { SetTempPixel(x-1,y,color2); SetTempPixel(x+1,y,color2); } else { SetTempPixel(x,y-1,color2); SetTempPixel(x,y+1,color2); } break; case 3: // 9 nodes if (x < 2) x+=2; if (y < 2) y+=2; if (x > BufferWi-3) x-=2; if (y > BufferHt-3) y-=2; SetTempPixel(x,y,color1); for (i=1; i<=2; i++) { SetTempPixel(x-i,y,color2); SetTempPixel(x+i,y,color2); SetTempPixel(x,y-i,color2); SetTempPixel(x,y+i,color2); } break; case 4: // 13 nodes if (x < 2) x+=2; if (y < 2) y+=2; if (x > BufferWi-3) x-=2; if (y > BufferHt-3) y-=2; SetTempPixel(x,y,color1); SetTempPixel(x-1,y,color2); SetTempPixel(x+1,y,color2); SetTempPixel(x,y-1,color2); SetTempPixel(x,y+1,color2); SetTempPixel(x-1,y+2,color2); SetTempPixel(x+1,y+2,color2); SetTempPixel(x-1,y-2,color2); SetTempPixel(x+1,y-2,color2); SetTempPixel(x+2,y-1,color2); SetTempPixel(x+2,y+1,color2); SetTempPixel(x-2,y-1,color2); SetTempPixel(x-2,y+1,color2); break; case 5: // 45 nodes (not enabled) break; } } } // move snowflakes int new_x,new_y,new_x2,new_y2; for (x=0; x<BufferWi; x++) { new_x = (x+state/20) % BufferWi; // CW new_x2 = (x-state/20) % BufferWi; // CCW if (new_x2 < 0) new_x2+=BufferWi; for (y=0; y<BufferHt; y++) { new_y = (y+state/10) % BufferHt; new_y2 = (new_y + BufferHt/2) % BufferHt; GetTempPixel(new_x,new_y,color1); if (color1.GetRGB() == 0) GetTempPixel(new_x2,new_y2,color1); SetPixel(x,y,color1); } } }
void RenderBuffer::SetTempPixel(int x, int y, const xlColor & color, int alpha) { xlColor c(color.Red(), color.Green(), color.Blue(), alpha); SetTempPixel(x, y, c); }
// use tempbuf for calculations void RgbEffects::RenderLife(int Count, int Type) { int i,x,y,cnt; bool isLive; wxColour color; Count=BufferWi * BufferHt * Count / 200 + 1; if (state == 0 || Count != LastLifeCount || Type != LastLifeType) { // seed tempbuf LastLifeCount=Count; LastLifeType=Type; ClearTempBuf(); for(i=0; i<Count; i++) { x=rand() % BufferWi; y=rand() % BufferHt; GetMultiColorBlend(rand01(),false,color); SetTempPixel(x,y,color); } } long TempState=state % 400 / 20; if (TempState == LastLifeState) { pixels=tempbuf; return; } else { LastLifeState=TempState; } for (x=0; x < BufferWi; x++) { for (y=0; y < BufferHt; y++) { GetTempPixel(x,y,color); isLive=(color.GetRGB() != 0); cnt=Life_CountNeighbors(x,y); switch (Type) { case 0: // B3/S23 /* Any live cell with fewer than two live neighbours dies, as if caused by under-population. Any live cell with two or three live neighbours lives on to the next generation. Any live cell with more than three live neighbours dies, as if by overcrowding. Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction. */ if (isLive && cnt >= 2 && cnt <= 3) { SetPixel(x,y,color); } else if (!isLive && cnt == 3) { GetMultiColorBlend(rand01(),false,color); SetPixel(x,y,color); } break; case 1: // B35/S236 if (isLive && (cnt == 2 || cnt == 3 || cnt == 6)) { SetPixel(x,y,color); } else if (!isLive && (cnt == 3 || cnt == 5)) { GetMultiColorBlend(rand01(),false,color); SetPixel(x,y,color); } break; case 2: // B357/S1358 if (isLive && (cnt == 1 || cnt == 3 || cnt == 5 || cnt == 8)) { SetPixel(x,y,color); } else if (!isLive && (cnt == 3 || cnt == 5 || cnt == 7)) { GetMultiColorBlend(rand01(),false,color); SetPixel(x,y,color); } break; case 3: // B378/S235678 if (isLive && (cnt == 2 || cnt == 3 || cnt >= 5)) { SetPixel(x,y,color); } else if (!isLive && (cnt == 3 || cnt == 7 || cnt == 8)) { GetMultiColorBlend(rand01(),false,color); SetPixel(x,y,color); } break; case 4: // B25678/S5678 if (isLive && (cnt >= 5)) { SetPixel(x,y,color); } else if (!isLive && (cnt == 2 || cnt >= 5)) { GetMultiColorBlend(rand01(),false,color); SetPixel(x,y,color); } break; } } } // copy new life state to tempbuf tempbuf=pixels; }