Yiff! screen fader algorithms

This document describes some of the screen fade algorigms present in the Yiff! game. I added these because the Allegro version faded the screen really really slowly and these were generally more interesting.

The fade code itself is in Yiff! distribution package, under screenfades.c. This uses Allegro for the actual graphics.

Munching Squares

Description

Pseudocode

Code: Clear screen

/*
  The Ancient Screen Clearing Hack from MIT's "HAKMEM" memo.
  The idea is simple: Screen is clobbered with the formula
  y = x XOR t.
  maxt parameter says the maximum t value. For 64x48 area to clean (with 10x10
  tiles, of course), I found 70 to be pretty good.
 */

void munch_clean(BITMAP *bitmap, int c, int maxt, int xsize, int ysize)
{
  int x,y,t;

  if(xsize % 10 != 0 || ysize % 10 != 0) {
    fprintf(stderr, "Error: Target size must be divisible by 10 (is %dx%d)\n",
	    xsize,ysize);
  }
  
  xsize /= 10; ysize /= 10;

  for(t=0; t<maxt; t++) {
    for(x=0; x <= xsize; x++) {
      y = (x)^(t); y %= ysize+1;
      rectfill(bitmap, x*10, y*10, x*10+10, y*10+10, c);
    }
    usleep(MUNCHWAIT);
  }
}

Code: Crossfade

/*
  This is the same thing, but does a cross-fade.
 */

void munch_crossfade(BITMAP *bitmap, BITMAP *to, int c, int maxt,
		     int xsize, int ysize)
{
  int x,y,t;

  if(xsize % 10 != 0 || ysize % 10 != 0) {
    fprintf(stderr,
      "munch_crossfade: Target size must be divisible by 10 (is %dx%d)\n",
	    xsize, ysize);
    return;
  }
  
  xsize /= 10; ysize /= 10;

  if(c < 0) {
    /* Do direct crossfade */
    for(t=0; t<maxt; t++) {
      for(x=0; x <= xsize; x++) {
	y = (x)^(t); y %= ysize+1;
	blit(bitmap, to, x*10, y*10, x*10, y*10, 10, 10);
      }
      usleep(MUNCHWAIT);
    }
  } else {
    /* Fade via color - unimplemented (but would be easy to do) */
  }
  /* Make sure the whole image was blitted */
  blit(bitmap, to, 0,0 , 0,0 , xsize*10, ysize*10);
}

"Blinds" sweep

Description

Pseudocode

Code

/*
  Does n33t gradual sweep (I call this a blind sweep).
  For idea source, see XScreenSaver.
 */

void blindsweep_clean(BITMAP *bitmap, int c, int xsize, int ysize)
{
  int y, n, w, a, b;

  ysize /= 10; /* We do this in steps of 10 anyway... */

  for(y=0; y < (ysize+4); y++) {
    for(n = y, w = 2; n >= 0 && w <= 10; n--, w += 2) {
      if(n < ysize) {
	a = (n*10)+(5-(w/2)); if(a<0) { a = 0; }
	b = (n*10)+(5+(w/2)); if(b<0) { b = 0; }
	rectfill(bitmap,0,a,xsize,b,c);
	usleep(SWEEPWAIT);
      }
    }
  }
}

[Index] [Up] [Main] [Weyfour WWWWolf]

Last modified: Wed Jun 14 17:59:15 EEST 2000