diff options
| author | Charles Cabergs <me@cacharle.xyz> | 2020-11-01 11:22:57 +0100 |
|---|---|---|
| committer | Charles Cabergs <me@cacharle.xyz> | 2020-11-01 11:22:57 +0100 |
| commit | 6f14e8ee1281b2384c926ebfabaa4da57c509b96 (patch) | |
| tree | 3f06b7ba1faf3100f4dec7484d2a05c500ac4733 | |
| parent | ea22cf13c1d2c09cf8102e8fd4277528a2a62455 (diff) | |
| download | cacharle.xyz-6f14e8ee1281b2384c926ebfabaa4da57c509b96.tar.gz cacharle.xyz-6f14e8ee1281b2384c926ebfabaa4da57c509b96.tar.bz2 cacharle.xyz-6f14e8ee1281b2384c926ebfabaa4da57c509b96.zip | |
Added old langton ant
| -rw-r--r-- | index.html | 1 | ||||
| -rw-r--r-- | utils/langton_ant/index.html | 16 | ||||
| -rw-r--r-- | utils/langton_ant/script.js | 68 | ||||
| -rw-r--r-- | utils/langton_ant/style.css | 14 |
4 files changed, 99 insertions, 0 deletions
@@ -27,6 +27,7 @@ <!--UTILSINDEX--> <li><a href="utils/rot13/index.html">rot13</a></li> <li><a href="utils/minesweeper/index.html">minesweeper</a></li> +<li><a href="utils/langton_ant/index.html">langton_ant</a></li> </ul> <h2>Links</h2> diff --git a/utils/langton_ant/index.html b/utils/langton_ant/index.html new file mode 100644 index 0000000..ad8ef22 --- /dev/null +++ b/utils/langton_ant/index.html @@ -0,0 +1,16 @@ +<!DOCTYPE html> +<html> + <head> + <link rel="stylesheet" type="text/css" href="../../style.css"/> + <link rel="stylesheet" type="text/css" href="style.css"/> + <meta charset="utf-8"/> + <title>cacharle - langton ant</title> + </head> + <body> + <h1>langton ant</h1> + <table id="table"> + </table> + <script type="text/javascript" src="https://code.jquery.com/jquery-3.2.1.min.js"></script> + <script type="text/javascript" src="script.js"></script> + </body> +</html> 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); +}); diff --git a/utils/langton_ant/style.css b/utils/langton_ant/style.css new file mode 100644 index 0000000..a42797c --- /dev/null +++ b/utils/langton_ant/style.css @@ -0,0 +1,14 @@ +body { + justify-content: center; +} + +td { + width: 3px; + height: 3px; +} + +table { + margin: auto; + border-spacing: 0px; + border-collapse: collapse; +} |
