Compare commits

..

No commits in common. "387b839410e879afdb07511e72703b86f617a05c" and "1bfcf5ac27bf383c282c65f052da255950396fd5" have entirely different histories.

2 changed files with 19 additions and 25 deletions

View File

@ -21,7 +21,7 @@
<ul>
<li>they/them</li>
<li>i like sysadmin</li>
<li>TODO: I really need this section to not read like garbo</li>
<li>TODO: I really need this section to not read like garbo<li>
</ul>
</div>

View File

@ -11,11 +11,10 @@ var walker_colors = [
"#8500ff", // purple
"#ff2e00", // red
];
// start with a random part of the sequence
var color_idx = Math.floor(Math.random() * walker_colors.length);
var color_idx = 0;
// create a new walker with random position and color
function create_random_walker() {
function create_new_walker() {
// create random-param walker and add to the array
var my_row = Math.floor(Math.random() * n_rows);
var my_col = Math.floor(Math.random() * n_cols);
@ -33,18 +32,15 @@ function create_random_walker() {
color_idx = (color_idx + 1).mod(walker_colors.length);
}
// kill the last walker created
function destroy_last_walker() {
var last_idx = walkers.length - 1;
var removed = walkers.splice(last_idx, 1)[0];
if (!removed) {
return;
}
// choose a random walker to kill. does not kill the trail.
function destroy_random_walker() {
// choose a random walker to destroy, draw black over its location.
var choice = Math.floor(Math.random() * walkers.length);
var removed = walkers.splice(choice, 1)[0];
draw_grid_square(removed.row, removed.col, "black");
// also stop its timer
var removed_timer = walker_timers.splice(last_idx, 1)[0];
var removed_timer = walker_timers.splice(choice, 1)[0];
clearInterval(removed_timer);
}
@ -85,20 +81,18 @@ Number.prototype.div = function(divisor) {
* Random walk implementation (movement functions) *
****************************************************************************/
// return a random update time. 10 to 90ms in increments of 20.
// return a random update time. 25 to 175ms in increments of 50
function random_update_time() {
var speed = Math.floor(Math.random() * 5);
return (speed * 20) + 10;
var speed = Math.floor(Math.random() * 4);
return (speed * 50) + 25;
}
// start up the functions that run FOREVER!!!
function init_walk() {
setInterval(update_trails, 200);
// create initial walkers of every color
for (var i = 0; i < walker_colors.length; i++) {
create_random_walker();
}
// create an initial walker. also creates its timer with setInterval.
create_new_walker();
}
// check if the trails array has a position.
@ -214,12 +208,12 @@ function fix_grid_size() {
// draw on the canvas a grid square of that color
function draw_grid_square(row, col, color) {
var margin = 1;
var margin = 2;
var pos_h = offset_h + (cell_size * col) + margin;
var pos_v = offset_v + (cell_size * row) + margin;
ctx.fillStyle = color;
ctx.fillRect(pos_h, pos_v, cell_size - margin, cell_size - margin);
ctx.fillRect(pos_h, pos_v, cell_size - (2*margin), cell_size - (2*margin));
}
/****************************************************************************
@ -240,16 +234,16 @@ window.addEventListener('resize', fix_grid_size);
// find the UI buttons and give them click handlers to activate our functions
document
.getElementById("button-create-walker")
.addEventListener("click", create_random_walker);
.addEventListener("click", create_new_walker);
document
.getElementById("button-destroy-walker")
.addEventListener("click", destroy_last_walker);
.addEventListener("click", destroy_random_walker);
document
.getElementById("button-reset-walkers")
.addEventListener("click", destroy_all_walkers);
// compute the initial rows and columns
var cell_size = 8;
var cell_size = 22;
var n_rows = canvas.height.div(cell_size);
var n_cols = canvas.width.div(cell_size);
var offset_h = (canvas.width - (cell_size * n_cols)).div(2);