Advertisement
NovaYoshi

Conway's Life the Sequel

Mar 18th, 2015
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.94 KB | None | 0 0
  1. float Size_Point = 0.1;
  2. vector Color_Point = <1,0,0>;
  3. list Particle_Parameters = [
  4. PSYS_SRC_TEXTURE, "",
  5. PSYS_PART_START_SCALE, < Size_Point, Size_Point, FALSE >,
  6. PSYS_PART_END_SCALE, < Size_Point, Size_Point, FALSE >,
  7. PSYS_PART_START_COLOR, Color_Point,
  8. PSYS_PART_END_COLOR, Color_Point,
  9.  
  10. PSYS_SRC_BURST_PART_COUNT, 1,
  11. PSYS_SRC_BURST_RATE, 0.0,
  12. PSYS_PART_MAX_AGE, 9.0,
  13.  
  14. PSYS_SRC_PATTERN, 1,
  15.  
  16. PSYS_PART_FLAGS,
  17. PSYS_PART_EMISSIVE_MASK
  18. ];
  19.  
  20. vector BoardSize = <2,2,0.1>;
  21. integer GridSize = 12;
  22. vector Origin;
  23. float Step;
  24. list Grid;
  25.  
  26. list makeArray ( integer rows, integer cols ) {
  27. integer i;
  28. list array = [];
  29. array += < rows, cols, 0 >;
  30. for (i=0; i < rows * cols; ++i) {
  31. array += (llFrand(1) < 0.25);
  32. }
  33. return array;
  34. }
  35. integer getElement( list array, integer row, integer col ) {
  36. vector metadata = llList2Vector( array, 0);
  37. integer cols = (integer)metadata.y;
  38. integer index = row * cols + col + 1;
  39. return llList2Integer( array, index);
  40. }
  41. list setElement( list array, integer row, integer col, integer value ) {
  42. vector metadata = llList2Vector( array, 0);
  43. integer cols = (integer)metadata.y;
  44. integer index = row * cols + col + 1;
  45. return llListReplaceList(array, [value], index, index);
  46. }
  47. integer Lookup(integer row, integer col) {
  48. return getElement(Grid, row % GridSize, col % GridSize);
  49. }
  50. integer Neighbors(integer row, integer col) {
  51. return Lookup(row, col+1)+
  52. Lookup(row+1, col+1)+
  53. Lookup(row+1, col)+
  54. Lookup(row+1, col-1)+
  55. Lookup(row, col-1)+
  56. Lookup(row-1, col-1)+
  57. Lookup(row-1, col)+
  58. Lookup(row-1, col+1);
  59. }
  60.  
  61. RunGrid() {
  62. list NewGrid = Grid;
  63.  
  64. llSetAlpha(1, ALL_SIDES);
  65. integer x; integer y; integer n;
  66. for(x=0;x<GridSize;x++) {
  67. for(y=0;y<GridSize;y++) {
  68. n = Neighbors(x, y);
  69. if(getElement(Grid, x,y)) {
  70. llSetLinkPrimitiveParamsFast( LINK_THIS, [PRIM_POSITION, Origin + <((float)x)*Step, ((float)y)*Step, 0>]);
  71. llParticleSystem( Particle_Parameters );
  72. llSleep(0.12);
  73. llParticleSystem( [] );
  74. if(n < 2 || n > 3) {
  75. NewGrid = setElement(NewGrid, x, y, 0);
  76. }
  77. } else if(n == 3){
  78. NewGrid = setElement(NewGrid, x, y, 1);
  79. }
  80. }
  81. }
  82. llSetAlpha(0, ALL_SIDES);
  83.  
  84. Grid = NewGrid;
  85. }
  86.  
  87. default
  88. {
  89. state_entry()
  90. {
  91. vector CSize = llGetScale();
  92. Step = BoardSize.x / GridSize;
  93. Origin = <-1, -1, 0.1> + <CSize.x, CSize.y, 0>;
  94.  
  95. Grid = makeArray(GridSize, GridSize);
  96. }
  97.  
  98. link_message(integer sender_num, integer num, string msg, key id)
  99. {
  100. llSetTimerEvent(10);
  101. RunGrid();
  102. }
  103.  
  104. timer() {
  105. RunGrid();
  106. }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement