1: 2: logic 3: { 4: // ~~~~~~~ Initial board layout 5: // 84|21 - {dead/cold/warm/hot}{void/copper/adamantine/earth} 6: // 0 = void 7: // 3 = earth 8: // 5 = copper - cold 9: // 9 = copper - warm 10: // 13 = copper - hot 11: // 6 = adamantine - cold 12: // 10 = adamantine - warm 13: // 14 = adamantine - hot 14: 15: array board 16: { 17: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18: 0, 0, 14, 0, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 6, 6, 0, 0, 0, 19: 0, 6, 0, 10, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 6, 0, 0, 20: 0, 6, 0, 6, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 6, 0, 6, 0, 21: 0, 0, 6, 0, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 6, 6, 6, 0, 22: 0, 0, 6, 0, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 6, 0, 0, 23: 0, 0, 6, 0, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 6, 0, 0, 24: 0, 6, 6, 6, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 6, 0, 0, 25: 0, 6, 0, 6, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 6, 0, 6, 0, 26: 0, 0, 6, 0, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 10, 0, 6, 0, 27: 0, 0, 0, 6, 6, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 14, 0, 0, 28: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 29: } 30: int boardwidth { 20 } 31: int boardheight { 12 } 32: 33: // Start / stop and zoom settings 34: int animate { 0 } 35: int zoom { 1 } 36: 37: // Scratch variable for test calculations 38: int hot {0} 39: int else {0} 40: 41: // Allow animation to be stopped/started 42: when {!animate} 43: allow {animate = 1;} 44: label {"start"} 45: when {animate} 46: allow {animate = 0;} 47: label {"stop"} 48: 49: // Zoom in/out actions 50: when {!animate and !zoom} 51: allow {zoom = 1;} 52: label {"zoom in"} 53: when {!animate and zoom} 54: allow {zoom = 0;} 55: label {"zoom out"} 56: 57: // Allow earth/copper toggle for all squares 58: for i (0 .. ((boardheight*boardwidth)-1)) 59: { 60: when {!animate and ((board[i] == 5) or (board[i] == 9) or (board[i] == 13))} 61: allow {board[i] = 3;} 62: label {"toggle " i} 63: 64: when {!animate and (board[i] == 3)} 65: allow {board[i] = 5;} 66: label {"toggle " i} 67: } 68: 69: // The magic tick 70: when {animate} 71: allow 72: { 73: for i (0 .. ((boardheight*boardwidth)-1)) 74: { 75: else = 1; 76: if ((board[i] & 12 == 8) or (board[i] & 12 == 12)) 77: { 78: board[i] = (board[i]+12) % 16; 79: else = 0; 80: } 81: if (else and (board[i] & 12 == 4)) 82: { 83: hot = 0; 84: if (board[i-1 ]&12 == 8) {hot++;} 85: if (board[i-(boardwidth+1)]&12 == 8) {hot++;} 86: if (board[i-boardwidth ]&12 == 8) {hot++;} 87: if (board[i-(boardwidth-1)]&12 == 8) {hot++;} 88: if (board[i+1 ]&12 == 12) {hot++;} 89: if (board[i+(boardwidth+1)]&12 == 12) {hot++;} 90: if (board[i+boardwidth ]&12 == 12) {hot++;} 91: if (board[i+(boardwidth-1)]&12 == 12) {hot++;} 92: 93: if ((hot == 1) or (hot == 2)) {board[i] = (board[i]+8) % 16;} 94: } 95: } 96: } 97: label {"tick"} 98: 99: // The not-so-magic tock 100: // Code must be kept identical to the tick above. 101: when {!animate} 102: allow 103: { 104: for i (0 .. ((boardheight*boardwidth)-1)) 105: { 106: else = 1; 107: if ((board[i] & 12 == 8) or (board[i] & 12 == 12)) 108: { 109: board[i] = (board[i]+12) % 16; 110: else = 0; 111: } 112: if (else and (board[i] & 12 == 4)) 113: { 114: hot = 0; 115: if (board[i-1 ]&12 == 8) {hot++;} 116: if (board[i-(boardwidth+1)]&12 == 8) {hot++;} 117: if (board[i-boardwidth ]&12 == 8) {hot++;} 118: if (board[i-(boardwidth-1)]&12 == 8) {hot++;} 119: if (board[i+1 ]&12 == 12) {hot++;} 120: if (board[i+(boardwidth+1)]&12 == 12) {hot++;} 121: if (board[i+boardwidth ]&12 == 12) {hot++;} 122: if (board[i+(boardwidth-1)]&12 == 12) {hot++;} 123: 124: if ((hot == 1) or (hot == 2)) {board[i] = (board[i]+8) % 16;} 125: } 126: } 127: } 128: label {"tock"} 129: } 130: 131: display 132: { 133: // Traguna Macoides Tracorum Satesdi! 134: repeatedly { "tick" } 135: 136: // Display 137: box {content {"Circuitry v0.7"}} 138: newline 139: 140: 141: 142: // Draw the board, assigning all the possible actions as we go 143: for y ( 0 .. (boardheight-1) ) 144: { 145: for x ( 0 .. (boardwidth-1) ) 146: { 147: box 148: { 149: bind_action { "toggle " ((y*boardwidth)+x) } 150: //content {"~"} 151: if (!zoom) 152: { 153: width { 3px } 154: height { 3px } 155: } 156: if (zoom) 157: { 158: width { 15px } 159: height { 15px } 160: } 161: 162: // Set background colour 163: background { #000 } 164: if (board[(y*boardwidth)+x] == 3) { background { #600 } } 165: if (board[(y*boardwidth)+x] == 5) { background { #f00 } } 166: if (board[(y*boardwidth)+x] == 9) { background { #f60 } } 167: if (board[(y*boardwidth)+x] == 13) { background { #fa0 } } 168: if (board[(y*boardwidth)+x] == 6) { background { #00f } } 169: if (board[(y*boardwidth)+x] == 10) { background { #06f } } 170: if (board[(y*boardwidth)+x] == 14) { background { #0af } } 171: } 172: } 173: newline 174: } 175: newline 176: 177: box {content {" "}} 178: newline 179: 180: box 181: { 182: content {"  Start  "} 183: bind_action {"start"} 184: background {#999} 185: while_active {background {#0f0}} 186: border { 1px solid #000 } 187: } 188: box {content {" "}} 189: box 190: { 191: content {"  Stop  "} 192: bind_action {"stop"} 193: background {#999} 194: while_active {background {#f00}} 195: border { 1px solid #000 } 196: } 197: box {content {" "}} 198: box 199: { 200: content {"  Tick  "} 201: bind_action {"tock"} 202: background {#999} 203: while_active {background {#ff0}} 204: border { 1px solid #000 } 205: } 206: newline 207: 208: box {height{3px}} 209: newline 210: box {content {"The stop button is a bit sticky so you might have to pound on it for a while..."}} 211: newline 212: box {height{3px}} 213: newline 214: 215: box 216: { 217: content {"  Zoom In  "} 218: bind_action {"zoom in"} 219: background {#999} 220: while_active {background {#00f}} 221: border { 1px solid #000 } 222: } 223: box {content {" "}} 224: box 225: { 226: content {"  Zoom Out  "} 227: bind_action {"zoom out"} 228: background {#999} 229: while_active {background {#00f}} 230: border { 1px solid #000 } 231: } 232: newline 233: 234: box {content {" "}} 235: newline 236: }