diff --git a/random-walkers.js b/random-walkers.js index 5251bfc..b91039e 100644 --- a/random-walkers.js +++ b/random-walkers.js @@ -63,6 +63,8 @@ Number.prototype.div = function(divisor) { function init_walk() { // Draw a grid of boxes on the canvas setInterval(draw, 20); + // TODO: it would be cool to have this changable, but I may just ... not + setInterval(move_walker, controls.step_time); /* @@ -89,14 +91,8 @@ function init_walk() { */ } -function move_walker(walker, possible_directions) { - // Update new random direction & update velocity of walker - var new_angle = Math.random() * 360 - walker.x_position = (walker.x_position + walker.x_velocity).mod(canvas.width); - walker.y_position = (walker.y_position + walker.y_velocity).mod(canvas.height); - walker.angle = degrees_to_radians(get_nearest_angle(new_angle, possible_directions)) - walker.x_velocity = walker.speed * Math.cos(walker.angle) - walker.y_velocity = walker.speed * Math.sin(walker.angle) +function move_walker() { + add_random_direction(walker_pos); } function add_random_direction(pos) { @@ -148,7 +144,6 @@ function draw() { // draw a colored square at the walker location draw_grid_square(walker_pos.row, walker_pos.col, "red"); - add_random_direction(walker_pos); // TODO CODE }