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

  1. /*
  2.  * File: heat.m256.c
  3.  *   By: Dave Hiebeler
  4.  *       hiebeler@turing.cs.rpi.edu
  5.  *       Feb. 1990
  6.  *
  7.  * The "heat" rule in the moore neighborhood.  Each cell finds the average
  8.  * value of the cells in the neighborhood; it then takes on that average
  9.  * as its new value, and adds an increment.
  10.  *
  11.  * parm2 is the increment that is added in after the cell takes on the
  12.  * local average value.
  13.  *
  14.  * parm2 = 2 is a good setting
  15.  *
  16.  * Note that parm1, the heat-constant, is not included in this rule as it
  17.  * was on the Sun-version of heat.m256. This is because the truncation
  18.  * in arithmetic on the CM prevents it from working well, unless you do
  19.  * some extra work in your arithmetic.
  20.  *
  21.  * Random starting images do interesting things with some settings of
  22.  * the parameter.  If the image just settles down to a uniform value
  23.  * (being uniformly incremented, if parm2 != 0), then I suggest starting
  24.  * with a uniform field of values around, say 0xf0 (240 decimal), and
  25.  * "punching a hole" of low values such as 0, in the middle.  The hole
  26.  * should be on the order of 40x40 squares, on a 256x256 array.  You can
  27.  * either construct sucn an image on the Sun and then send it to the CM,
  28.  * or use "CM/General_random" to do it all directly on the CM.
  29.  */
  30.  
  31.  
  32. #include "CMnborhood.h"
  33.  
  34. byte heat(), heat_exit();
  35. static CM_field_id_t heat_sum;
  36.  
  37.  
  38. void
  39. init_function()
  40. {
  41.  
  42.     update_function = heat;
  43.     exit_function = heat_exit;
  44.     parm2 = 2;
  45.     heat_sum = CM_allocate_heap_field(15);
  46. }
  47.  
  48.  
  49. byte
  50. heat()
  51. {
  52.     CM_u_move_2L(heat_sum, MNorth, 15, 8);
  53.     CM_u_add_3_3L(heat_sum, heat_sum, MSouth, 12, 12, 8);
  54.     CM_u_add_3_3L(heat_sum, heat_sum, MEast, 12, 12, 8);
  55.     CM_u_add_3_3L(heat_sum, heat_sum, MWest, 12, 12, 8);
  56.     CM_u_add_3_3L(heat_sum, heat_sum, MNW, 12, 12, 8);
  57.     CM_u_add_3_3L(heat_sum, heat_sum, MSW, 12, 12, 8);
  58.     CM_u_add_3_3L(heat_sum, heat_sum, MNE, 12, 12, 8);
  59.     CM_u_add_3_3L(heat_sum, heat_sum, MSE, 12, 12, 8);
  60.     CM_u_add_3_3L(heat_sum, heat_sum, MCenter, 12, 12, 8);
  61.     CM_u_truncate_constant_2_1L(heat_sum, 9, 12);
  62.     CM_u_add_constant_2_1L(heat_sum, parm2, 8);
  63.     CM_u_move_1L(cell, heat_sum, 8);
  64. }
  65.  
  66.  
  67. byte
  68. heat_exit()
  69. {
  70.     CM_deallocate_heap_field(heat_sum);
  71. }
  72.