home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Linux / Divers / bomb.tar.gz / bomb.tar / bomb / slip.c < prev    next >
C/C++ Source or Header  |  1997-06-22  |  4KB  |  175 lines

  1. /*
  2.     bomb - automatic interactive visual stimulation
  3.     Copyright (C) 1995  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. #include "bomb.h"
  22.  
  23. void
  24. blit(image8_t *fb, int x, int y, int dx, int dy, int bsize) {
  25.   u_char *line_base, *p;
  26.   int blit_offset, ix, iy, i, j;
  27.      
  28.   blit_offset = fb->stride * dy + dx;
  29.   line_base = fb->p + x + (y * fb->stride);
  30.  
  31.   if (dx > 0) {
  32.     ix = -1;
  33.     line_base += bsize - 1;
  34.   } else
  35.     ix = 1;
  36.   if (dy > 0) {
  37.     iy = -fb->stride;
  38.     line_base += fb->stride * (bsize - 1);
  39.   } else
  40.     iy = fb->stride;
  41.   for (j = 0; j < bsize; j++) {
  42.     p = line_base;
  43.     for (i = 0; i < bsize; i++) {
  44.       p[blit_offset] = *p;
  45.       p += ix;
  46.     }
  47.     line_base += iy;
  48.   }
  49. }
  50.  
  51. void
  52. step_rule_slip(int frame, rule_t *p, image8_t *fb) {
  53.    int i, j, k;
  54.    board_t *sboard, *dboard;
  55.    u_char *lp;
  56.    int ib;
  57.    int field = iclamp(p->brain, 6);
  58.    int bsize = 30;
  59.    int max_delta = 5;
  60. #if 0
  61.    bsize = p->drift_speed*3;
  62.    if (bsize < 10) bsize = 10;
  63.    else if (bsize > 64) bsize = 64;
  64. #endif
  65.    switch (field) {
  66.     case 4:
  67.       spiral(&board3[0], frame * (6.28 / 560), frame%20, 20);
  68.       if (1) {
  69.     /* creeping edges */
  70.     int b = bsize/2;
  71.     int w = (fb->width-b);
  72.     int h = (fb->height-b);
  73.     switch (R%4) {
  74.     case 0: blit(fb, 0, R%h,  1, 0, b); break;
  75.     case 1: blit(fb, w, R%h, -1, 0, b); break;
  76.     case 2: blit(fb, R%w, 0, 0,  1, b); break;
  77.     case 3: blit(fb, R%w, h, 0, -1, b); break;
  78.     }
  79.       }
  80.       break;
  81.     case 5:
  82.       bsize = 20;
  83.       if (grad_state++ < 20)
  84.      image2grad(&board2[dbuf], &board3[0], 15, frame%20, 20);
  85.       break;
  86.    }
  87.  
  88.    /* adjust this to even out frame rate */
  89.    for (ib = 0; ib < 70; ib++) {
  90.       int dx, dy;
  91.       int x = max_delta + R%(fb->width  - (bsize + 2*max_delta));
  92.       int y = max_delta + R%(fb->height - (bsize + 2*max_delta));
  93.       double t, tx, ty, s1, s2;
  94.  
  95.       switch (field) {
  96.        case 0:
  97.      dx = R8b%3 - 1;
  98.      dy = R8b%3 - 1;
  99.      break;
  100.        case 1:
  101.      tx = 2 * x / (double) fb->width - 1;
  102.      ty = 2 * y / (double) fb->height - 1;
  103.      s1 = -ty;
  104.      s2 = tx;
  105.      dx = quantize(s1);
  106.      dy = quantize(s2);
  107.      break;
  108.        case 2:
  109.      tx = 2 * x / (double) fb->width - 1;
  110.      ty = 2 * y / (double) fb->height - 1;
  111.  
  112.      if (ty < 0) {
  113.         ty = ty + 0.05;
  114.         if (ty > 0)
  115.            ty = 0.0;
  116.      }
  117.      if (ty > 0) {
  118.         ty = ty - 0.05;
  119.         if (ty < 0)
  120.            ty = 0.0;
  121.      }
  122.       
  123.      t = tx * tx + ty * ty + 1e-5;
  124.      s1 = 2 * tx * tx / t - 1;
  125.      s2 = 2 * tx * ty / t;
  126.      if (0) {
  127.        double scale = ((p->drift_speed - 10)/20.0 + 1);
  128.        if (scale > 5.0) scale = 5.0;
  129.        if (scale < 0.2) scale = 0.2;
  130.  
  131.        s1 *= 2 * scale;
  132.        s2 *= 2 * scale;
  133.      }
  134.      dx = quantize(s1);
  135.      dy = quantize(s2);
  136.      break;
  137.        case 3:
  138.      tx = 2 * x / (double) fb->width - 1;
  139.      ty = 2 * y / (double) fb->height - 1;
  140.      s1 = tx;
  141.      s2 = ty;
  142.      dx = quantize(s1);
  143.      dy = quantize(s2);
  144.      break;
  145.        case 4:
  146.      if (1) {
  147.         int dxdy = board3[0][x][y];
  148.         s1 = ((dxdy >> 8) - 128) / 64.0;
  149.         s2 = ((dxdy & 255) - 128) / 64.0;
  150.      }
  151.      dx = quantize(s1);
  152.      dy = quantize(s2);
  153.      break;
  154.        case 5:
  155.      if (1) {
  156.         int dxdy = board3[0][x][y];
  157.         int xi = ((dxdy >> 8) - 128);
  158.         int yi = ((dxdy & 255) - 128);
  159.         int p = (xi * xi + yi * yi);
  160.         if (p) {
  161.            double r = 4.0 / sqrt(p);
  162.            dx = quantize(-yi * r);
  163.            dy = quantize(xi * r);
  164.         } else {
  165.            dx = R8b%3 - 1;
  166.            dy = R8b%3 - 1;
  167.         }
  168.      }
  169.      break;
  170.       }
  171.  
  172.       blit(fb, x, y, dx, dy, bsize);
  173.    }
  174. }
  175.