home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Linux / Divers / bomb.tar.gz / bomb.tar / bomb / quad.c < prev    next >
C/C++ Source or Header  |  1997-07-12  |  2KB  |  69 lines

  1. /*
  2.     bomb - automatic interactive visual stimulation
  3.     Copyright (C) 1994  Scott Draves <spot@cs.cmu.edu>
  4.  
  5.     This program is free software; you can redistribute it and/or modify
  6.     it under the terms of the GNU General Public License as published by
  7.     the Free Software Foundation; either version 2 of the License, or
  8.     (at your option) any later version.
  9.  
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU General Public License
  16.     along with this program; if not, write to the Free Software
  17.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19.  
  20. #include "defs.h"
  21.  
  22. void
  23. step_rule_quad(int frame, rule_t *p, image8_t *fb) {
  24.    int x,y,bx,by;    
  25.    board_t *sboard, *dboard;
  26.    int bm = p->brain & 31;
  27.    u_char *lp, *lp1;
  28.    int speed = (p->speed >>2);
  29.  
  30.    bm = 408 + ((bm>>2) | ((bm&3)<<3));
  31.  
  32.    sboard = &board[dbuf];
  33.    dboard = &board[1-dbuf];
  34.    dbuf = 1-dbuf;
  35.  
  36.  
  37.    for(y=0;y<=YSIZE+1;y++) {
  38.       (*sboard)[0][y] = (*sboard)[SMALL_XSIZE][y];
  39.       (*sboard)[SMALL_XSIZE+1][y] = (*sboard)[1][y];
  40.    }
  41.    for(x=0;x<=SMALL_XSIZE+1;x++) {
  42.       (*sboard)[x][0] = (*sboard)[x][YSIZE];
  43.       (*sboard)[x][YSIZE+1] = (*sboard)[x][1];
  44.    }
  45.  
  46.    for (y=1;y<=YSIZE;y++) {
  47.       /* why not an additional -1 for x? */
  48.       lp = fb->p + (fb->stride * (y - 1));
  49.       lp1 = fb->p + (fb->stride * (y - 1)) + XSIZE-2;
  50.       for (x=1;x<=SMALL_XSIZE;x++) {
  51.      int t;
  52.      int c = (*sboard)[x][y];
  53.      t = c;
  54.      t = ((t>>1) * (65535 - t))>>8;
  55.      t = (bm * t) >> 7;
  56.      t = (t>>6)&65535;
  57.      t = (((t*10) + speed +
  58.            ((*sboard)[x-1][y  ])+
  59.            (((*sboard)[x  ][y-1])<<1)+
  60.            (((*sboard)[x+1][y  ]))+
  61.            (((*sboard)[x  ][y+1])<<1)) >> 4);
  62.      if (t < 0) t = 0;
  63.      (*dboard)[x][y] = t;
  64.      *lp1-- = t;
  65.      *(lp++) = t;
  66.       }
  67.    }
  68. }
  69.