<commit_before>var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");

// Configuration.
var kStartColor = "#00FF00"
var kGoalColor = "#FF0000"
var kLineColor = "#CCCCCC";
var kFinalPathColor = "#0000FF";
var kStartGoalRadius = 10;
var kDeltaQ = 20.0;
var kGoalBias = 0.1;
var kGoalTestDistance = 21.0;

function RandomStart() {
  let width = c.width;
  let height = c.height;
  let sx = Math.random() * width / 4 + 3 * width / 4;
  let sy = Math.random() * height / 4 + 3 * height / 4;
  start = [sx, sy];
}

function RandomGoal() {
  let width = c.width;
  let height = c.height;
  let sx = Math.random() * width / 4;
  let sy = Math.random() * height / 4;
  goal = [sx, sy];
}

function RandomPoint() {
  if (Math.random() <= kGoalBias) {
    return goal;
  }
  let width = c.width;
  let height = c.height;
  let sx = Math.random() * width;
  let sy = Math.random() * height;
  return [sx, sy];
}

function DrawLine(p1, p2, color) {
  ctx.strokeStyle = color;
  ctx.beginPath();
  ctx.moveTo(p1[0], p1[1]);
  ctx.lineTo(p2[0], p2[1]);
  ctx.stroke();
}

function DrawCircle(point, radius, color) {
  ctx.strokeStyle = color;
  ctx.beginPath();
  ctx.arc(point[0], point[1], radius, 0, 2 * Math.PI);
  ctx.stroke();
}

function NeedsReset() {
  return ((c.width != document.body.clientWidth) ||
  (c.height != document.body.clientHeight) || GoalTest(ClosestInTree(goal)));
}

function ClearCanvas() {
  c.width = document.body.clientWidth; //document.width is obsolete
  c.height = document.body.clientHeight; //document.height is obsolete
}

function Reset() {
  ClearCanvas();
  RandomStart();
  RandomGoal();
  tree = [[start, start]];
  DrawCircle(start, kStartGoalRadius, kStartColor)
  DrawCircle(goal, kStartGoalRadius, kGoalColor)
}

function AddVecs(v1, v2) {
  return [v1[0] + v2[0], v1[1] + v2[1]];
}

function SubVecs(v1, v2) {
  return [v1[0] - v2[0], v1[1] - v2[1]];
}

function ScaleVec(vec, scale) {
  return [vec[0] * scale, vec[1] * scale];
}

function Sq(x) {
  return (x * x);
}

function Dist(a, b) {  
  return Math.sqrt(Sq(a[0] - b[0]) + Sq(a[1] - b[1]));
}

function GoalTest(point) {
  return (Dist(point, goal) < kGoalTestDistance);
}

function ClosestInTree(sample) {
  var closest = tree[0][0];
  for (var i = 1; i < tree.length; ++i) {
    let e = tree[i][0];
    if (Dist(sample, closest) > Dist(sample, e)) {
      closest = e;
    }
  }
  return closest;
}

function SteerPoint(start, steering) {
  let dist = Dist(start, steering);
  let subed_vec = SubVecs(steering, start);
  let scaled_vec = ScaleVec(subed_vec, kDeltaQ / dist);
  return AddVecs(start, scaled_vec);
}

function GetParent(point) {
  for (var i = 0; i < tree.length; ++i) {
    if (tree[i][0] === point) {
      return tree[i][1];
    }
  }
  console.log("Could not find parent of " + point);
  return start;
}

function UnwindPath(line_end) {
  let curr = line_end;
  while (curr != start) {
    let parent = GetParent(curr);
    DrawLine(curr, parent, kFinalPathColor);
    curr = parent;
  }
}

function MainLoop() {
  if (NeedsReset()) {
    Reset();
  }
  let sample_point = RandomPoint();
  let closest_in_tree = ClosestInTree(sample_point);
  let line_end = SteerPoint(closest_in_tree, sample_point);
  DrawLine(closest_in_tree, line_end, kLineColor);
  tree.push([line_end, closest_in_tree]);

  if (GoalTest(line_end)) {
    UnwindPath(line_end);
    setTimeout(MainLoop, 2000);
  } else {
    setTimeout(MainLoop, 100);
  }
}

// Kick it all off!
MainLoop();
<commit_msg>Made finished blue less obnoxious<commit_after>var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");

// Configuration.
var kStartColor = "#00FF00"
var kGoalColor = "#FF0000"
var kLineColor = "#CCCCCC";
var kFinalPathColor = "#9999FF";
var kStartGoalRadius = 10;
var kDeltaQ = 20.0;
var kGoalBias = 0.1;
var kGoalTestDistance = 21.0;

function RandomStart() {
  let width = c.width;
  let height = c.height;
  let sx = Math.random() * width / 4 + 3 * width / 4;
  let sy = Math.random() * height / 4 + 3 * height / 4;
  start = [sx, sy];
}

function RandomGoal() {
  let width = c.width;
  let height = c.height;
  let sx = Math.random() * width / 4;
  let sy = Math.random() * height / 4;
  goal = [sx, sy];
}

function RandomPoint() {
  if (Math.random() <= kGoalBias) {
    return goal;
  }
  let width = c.width;
  let height = c.height;
  let sx = Math.random() * width;
  let sy = Math.random() * height;
  return [sx, sy];
}

function DrawLine(p1, p2, color) {
  ctx.strokeStyle = color;
  ctx.beginPath();
  ctx.moveTo(p1[0], p1[1]);
  ctx.lineTo(p2[0], p2[1]);
  ctx.stroke();
}

function DrawCircle(point, radius, color) {
  ctx.strokeStyle = color;
  ctx.beginPath();
  ctx.arc(point[0], point[1], radius, 0, 2 * Math.PI);
  ctx.stroke();
}

function NeedsReset() {
  return ((c.width != document.body.clientWidth) ||
  (c.height != document.body.clientHeight) || GoalTest(ClosestInTree(goal)));
}

function ClearCanvas() {
  c.width = document.body.clientWidth; //document.width is obsolete
  c.height = document.body.clientHeight; //document.height is obsolete
}

function Reset() {
  ClearCanvas();
  RandomStart();
  RandomGoal();
  tree = [[start, start]];
  DrawCircle(start, kStartGoalRadius, kStartColor)
  DrawCircle(goal, kStartGoalRadius, kGoalColor)
}

function AddVecs(v1, v2) {
  return [v1[0] + v2[0], v1[1] + v2[1]];
}

function SubVecs(v1, v2) {
  return [v1[0] - v2[0], v1[1] - v2[1]];
}

function ScaleVec(vec, scale) {
  return [vec[0] * scale, vec[1] * scale];
}

function Sq(x) {
  return (x * x);
}

function Dist(a, b) {  
  return Math.sqrt(Sq(a[0] - b[0]) + Sq(a[1] - b[1]));
}

function GoalTest(point) {
  return (Dist(point, goal) < kGoalTestDistance);
}

function ClosestInTree(sample) {
  var closest = tree[0][0];
  for (var i = 1; i < tree.length; ++i) {
    let e = tree[i][0];
    if (Dist(sample, closest) > Dist(sample, e)) {
      closest = e;
    }
  }
  return closest;
}

function SteerPoint(start, steering) {
  let dist = Dist(start, steering);
  let subed_vec = SubVecs(steering, start);
  let scaled_vec = ScaleVec(subed_vec, kDeltaQ / dist);
  return AddVecs(start, scaled_vec);
}

function GetParent(point) {
  for (var i = 0; i < tree.length; ++i) {
    if (tree[i][0] === point) {
      return tree[i][1];
    }
  }
  console.log("Could not find parent of " + point);
  return start;
}

function UnwindPath(line_end) {
  let curr = line_end;
  while (curr != start) {
    let parent = GetParent(curr);
    DrawLine(curr, parent, kFinalPathColor);
    curr = parent;
  }
}

function MainLoop() {
  if (NeedsReset()) {
    Reset();
  }
  let sample_point = RandomPoint();
  let closest_in_tree = ClosestInTree(sample_point);
  let line_end = SteerPoint(closest_in_tree, sample_point);
  DrawLine(closest_in_tree, line_end, kLineColor);
  tree.push([line_end, closest_in_tree]);

  if (GoalTest(line_end)) {
    UnwindPath(line_end);
    setTimeout(MainLoop, 2000);
  } else {
    setTimeout(MainLoop, 100);
  }
}

// Kick it all off!
MainLoop();

{'fraction_non_alphanumeric': 0.1647226173541963, 'fraction_numerical': 0.02418207681365576, 'mean_word_length': 3.665560716655607, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '697761', 'n_tokens_mistral': 2805, 'n_tokens_neox': 2706, 'n_words': 644}