home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / cellsim / v2_5 / rule_src / heatm256.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-02-26  |  1.1 KB  |  48 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.  
  28.  
  29. void
  30. init_function()
  31. {
  32.     update_function = heat;
  33.     parm1 = 100;
  34.     parm2 = 2;
  35. }
  36.  
  37.  
  38. byte
  39. heat(nbors)
  40. moore_nbors *nbors;
  41. {
  42.     int heat_avg;
  43.  
  44.     Get_moore_nbors;
  45.     heat_avg = (tl + l + bl + t + c + b + tr + r + br) / 9;
  46.     return (byte)((c + (heat_avg - c) * parm1 / 100 + parm2) % 256);
  47. }
  48.