home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Linux / Divers / bomb.tar.gz / bomb.tar / bomb / rug_rug.c < prev    next >
C/C++ Source or Header  |  1997-04-25  |  3KB  |  111 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.  
  23. /* to eliminate blockiness, consider annealing the results of the first rug
  24.    before driving the second.  or just figure out how to run a high
  25.    resolution rug that boils at low spatial frequencies, perhapse by
  26.    increasing the speed of light. */
  27.  
  28. static slow_frames = 0;
  29.  
  30. void step_rule_rug_rug(int frame, rule_t *p, image8_t *fb)
  31. {
  32.    int x, y, bx, by;
  33.    static int debt = 0;
  34.    board_t *s_heat_board, *d_heat_board;
  35.    board_t *s_game_board, *d_game_board;
  36.    u_char *lp;
  37.  
  38.    dbuf = frame&1;
  39.    s_heat_board=&board[dbuf];
  40.    d_heat_board=&board[1-dbuf];
  41.    dbuf = slow_frames&1;
  42.    s_game_board=&board2[dbuf];
  43.    d_game_board=&board2[1-dbuf];
  44.  
  45.    if (-1 == p->driver_slowdown ||
  46.        ((p->driver_slowdown > 0) &&
  47.         0 == (frame % p->driver_slowdown))) {
  48.        slow_frames++;
  49.  
  50.    /* torus */
  51.    for(y=0;y<=VSMALL_YSIZE+1;y++) {
  52.       (*s_game_board)[0][y] = (*s_game_board)[VSMALL_XSIZE][y];
  53.       (*s_game_board)[VSMALL_XSIZE+1][y] = (*s_game_board)[1][y];
  54.    }
  55.    for(x=0;x<=VSMALL_XSIZE+1;x++) {
  56.       (*s_game_board)[x][0] = (*s_game_board)[x][VSMALL_YSIZE];
  57.       (*s_game_board)[x][VSMALL_YSIZE+1] = (*s_game_board)[x][1];
  58.    }
  59.  
  60.       for(y=1;y<=VSMALL_YSIZE;y++) {
  61.      for(x=1;x<=VSMALL_XSIZE;x++) {
  62.         int heat, t;
  63.         heat = ((((*s_game_board)[x  ][y-1]) +
  64.              ((*s_game_board)[x-1][y  ]<<1) +
  65.              ((*s_game_board)[x  ][y  ]<<1) +
  66.              ((*s_game_board)[x+1][y  ]<<1) +
  67.              ((*s_game_board)[x  ][y+1])) >> 3);
  68.         heat--;
  69.         heat &= 471;
  70.         (*d_game_board)[x][y]= heat;
  71.      }
  72.       }
  73.       }
  74.  
  75.    for(y=0;y<=YSIZE+1;y++) {
  76.       (*s_heat_board)[0][y] = (*s_heat_board)[XSIZE][y];
  77.       (*s_heat_board)[XSIZE+1][y] = (*s_heat_board)[1][y];
  78.    }
  79.    for(x=0;x<=XSIZE+1;x++) {
  80.       (*s_heat_board)[x][0] = (*s_heat_board)[x][YSIZE];
  81.       (*s_heat_board)[x][YSIZE+1] = (*s_heat_board)[x][1];
  82.    }
  83.  
  84.    for (y=1;y<=YSIZE;y++) {
  85.       lp = fb->p + (fb->stride * (y - 1));
  86.       for (x=1;x<=XSIZE;x++) {
  87.      int heat, t;
  88.      heat = ((((*s_heat_board)[x  ][y-1]<<1) +
  89.           ((*s_heat_board)[x-1][y  ]) +
  90.           ((*s_heat_board)[x  ][y  ]<<1) +
  91.           ((*s_heat_board)[x+1][y  ]) +
  92.           ((*s_heat_board)[x  ][y+1]<<1)) >> 3);
  93.      /* just >> rounds wrong, but close enough */
  94.      t = (*s_game_board)[x>>3][y>>3];
  95.      t = 20 < t;
  96.      if (t)
  97.         heat += p->speed;
  98.      else
  99.         heat -= p->speed;
  100.  
  101.      heat &= p->mask;
  102.      
  103.      (*d_heat_board)[x][y]= heat;
  104.     // if (p->remap)
  105.         heat = remap[heat];
  106.      /* heat = t ? 0 : 100; */
  107.      *(lp++) = heat;
  108.       }
  109.    }
  110. }
  111.