void Graph::halfTone(Color color){ int megaPixel = 3; Vector v; Color tmp; int numberOfPixels; //backup before doing half-toning backupPixelBuffer(); for(int r = 0 ; r < window_height; r+=megaPixel){ //row for(int c = 0 ; c < window_width; c+=megaPixel){//col v = {0,0,0}; for(int i = r; i < r+megaPixel ; i++){ // 3 by 3 for(int j = c; j < c+megaPixel; j++ ){ //DPRINT("r %d, c %d, i %d, j %d\n", r, c, i,j); tmp = readPixel(j,i); if( equal(tmp, background_color) ) v = add( v, {1, 1, 1} ); else v = add( v, ctov( tmp ) ); } } //write each mega pixel numberOfPixels = round( 9- (v.x + v.y + v.z) / 3 ); drawMegaPixel(numberOfPixels, megaPixel * 3, r, c, color); } } }
void renderEffect(Image* output, double elapsedTime) { float pixelsPerSecond = 200.f; int scrollPosition = (int) fmod(elapsedTime * pixelsPerSecond, (double) (2 * ScreenWidth)) - ScreenWidth; for (int y = 0; y < ScreenHeight; y++) for (int x = 0; x < ScreenWidth; x++) { FloatRGBColor color = readPixel(originalImage, x + scrollPosition, y); drawPixel(output, x, y, color); } }
void renderEffect(Image* output, double elapsedTime) { float distortStepTimeScale = 5.f; float distortStepY = 0.2f; float widthStepTimeScale = 0.2f; float widthStepY = 0.02f; float distortMaxWidth = 20.f; for (int y = 0; y < ScreenHeight; y++) { float maxWidth = (float) (sin(elapsedTime * widthStepTimeScale + y * widthStepY) * distortMaxWidth); int scrollPosition = (int) (sin(elapsedTime * distortStepTimeScale + y * distortStepY) * maxWidth); for (int x = 0; x < ScreenWidth; x++) { FloatRGBColor color = readPixel(originalImage, x + scrollPosition, y); drawPixel(output, x, y, color); } } }