aboutsummaryrefslogtreecommitdiff
path: root/utils/langton_ant/script.js
diff options
context:
space:
mode:
Diffstat (limited to 'utils/langton_ant/script.js')
-rw-r--r--utils/langton_ant/script.js68
1 files changed, 68 insertions, 0 deletions
diff --git a/utils/langton_ant/script.js b/utils/langton_ant/script.js
new file mode 100644
index 0000000..b5405a3
--- /dev/null
+++ b/utils/langton_ant/script.js
@@ -0,0 +1,68 @@
+// This was coded a very long time ago and I put it here for posterity
+// Please don't judge me too harshly
+// I was young and naive
+$(function() {
+ let x = 100;
+ let y = 100;
+
+ function table_generator() {
+ for (let i = 0; i < x; i++) {
+ $('#table').append('<tr class="' + i + '"></tr>');
+ for (let j = 0; j < y; j++) {
+ $('#table tr[class="' + i + '"]').append('<td class="' + j + '"></td>');
+ }
+ }
+ }
+
+ table_generator();
+ let case_index = [Math.floor(x/2), Math.floor(y/2)];
+ let case_table = $('#table tr[class="' + case_index[0] + '"] td[class="' + case_index[1] + '"]');
+ case_table.css('background-color', 'black');
+ let direction = 0;
+
+ function case_change() {
+ // up = 0
+ // left = 1
+ // bot = 2
+ // right = 3
+
+ switch (direction) {
+ case 0:
+ case_index[0] = case_index[0] - 1;
+ break;
+ case 1:
+ case_index[1] = case_index[1] - 1;
+ break;
+ case 2:
+ case_index[0] = case_index[0] + 1;
+ break;
+ case 3:
+ case_index[1] = case_index[1] + 1;
+ break;
+ }
+ }
+
+ function update() {
+ if (case_table.css('background-color') == 'rgb(0, 0, 0)') {
+ if (direction == 3) {
+ direction = 0;
+ } else {
+ direction = direction + 1;
+ }
+ case_table.css('background-color', 'white');
+ case_change();
+ case_table = $('#table tr[class="' + case_index[0] + '"] td[class="' + case_index[1] + '"]');
+ } else {
+ if (direction == 0) {
+ direction = 3;
+ } else {
+ direction = direction - 1;
+ }
+ case_table.css('background-color', 'black');
+ case_change();
+ case_table = $('#table tr[class="' + case_index[0] + '"] td[class="' + case_index[1] + '"]');
+ }
+ }
+
+ setInterval(update, 10);
+});