home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / cellsim / v2_5 / rule_src / het2m256.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-02-26  |  1.5 KB  |  73 lines

  1. /*
  2.  * File: heat.m256.c
  3.  *   By: Dave Hiebeler
  4.  *       hiebeler@turing.cs.rpi.edu
  5.  *       August 1989
  6.  *
  7.  * The "heat" rule in the moore neighborhood.  Each cell finds the average
  8.  * value of the cells in the neighborhood; it then moves toward that
  9.  * average, and adds an increment.
  10.  *  If h = the heat at the current cell, and H = the average heat in the
  11.  * neighborhood, and dH = the difference between them, then this is what
  12.  * happens:
  13.  *   h = h + (dH * (parm1/100)) + parm2
  14.  *
  15.  * Thus, parm1 is the "heat constant" which controls how quickly heat
  16.  * will diffuse, and parm2 is an increment that is added in after the
  17.  * cell moves toward the local average.
  18.  *
  19.  * Try this with parm1 = 100 and parm2 = 2, starting from the "heat.64x"
  20.  * image.
  21.  */
  22.  
  23.  
  24. #include "nborhood.h"
  25.  
  26. byte heat();
  27. void before_func(), after_func();
  28.  
  29. static int hsum=0;
  30.  
  31. void
  32. heat_init()
  33. {
  34.     update_function = heat;
  35.     before_function = before_func;
  36.     after_function = after_func;
  37.     parm1 = 100;
  38.     parm2 = 2;
  39. }
  40.  
  41.  
  42. byte
  43. heat(nbors)
  44. moore_nbors *nbors;
  45. {
  46.     int heat_avg;
  47.  
  48.     Get_moore_nbors;
  49.     hsum += c;
  50.     heat_avg = (tl + l + bl + t + c + b + tr + r + br) / 9;
  51.     return (byte)((c + (heat_avg - c) * parm1 / 100 + parm2) % 256);
  52. }
  53.  
  54.  
  55. void
  56. before_func(array_info)
  57. array_info_struct *array_info;
  58. {
  59.     printf("setting hsum to 0\n");
  60.     hsum = 0;
  61. }
  62.  
  63.  
  64. void
  65. after_func(array_info)
  66. array_info_struct *array_info;
  67. {
  68.     int size;
  69.  
  70.     size = array_info->size;
  71.     printf("h-average = %d\n", hsum / (size*size));
  72. }
  73.