<commit_before>// -- settings, immutable -- //
var BRIGHTNESS_FACTOR = 10; // Higher = brighter
var STAR_SIZE_PIXELS = 1.5;
var STAR_RANGE_INDICES = 10; // Higher = more random looking, comp expensive
var LEVEL_DEPTH = 5; // Higher = more (faint) stars, comp expensive

// TODO:
// - touchscreen support
// - resize / fullscreen
// - older browsers / polyfill

var MAX_INT = -1 >>> 1;

// -- zoom and pan, altered by listeners -- //
var offsetX = 0; // Top left has this x coordinate in world frame.
var offsetY = 0;
// scale of 1 means 1 world unit = 1 canvas pixel
// scale of 100 means 1 world unit = 100 canvas pixels
var scale = 1;

var canvas = document.getElementById("starfield");
canvas.style['background-color'] = 'black';
var context = canvas.getContext('2d');

var timestamps = [];

var cache = new RRCache(100000);
function cachedMD5(to_hash) {
  var cached = cache.get(to_hash);
  if (cached) return cached; else {
    var digest = SparkMD5.hash(to_hash, true);
    cache.set(to_hash, digest);
    return digest;
  }
}

function render() {
  var worldWidth = canvas.width / scale;
  var worldHeight = canvas.height / scale;

  // The level at which you would expect one star in current viewport.
  var levelForCurrentScale = - Math.log(worldWidth * worldHeight) / 2
  var startLevel = Math.floor(levelForCurrentScale);
  context.clearRect(0, 0, canvas.width, canvas.height);

  for (level = startLevel; level < startLevel + LEVEL_DEPTH; level++) {
    var spacing = Math.exp(-level);
    for (
      xIndex = Math.floor(offsetX / spacing) - STAR_RANGE_INDICES;
      xIndex <= Math.ceil((offsetX + worldWidth) / spacing)
        + STAR_RANGE_INDICES;
      xIndex++
    ) {
      for (
        yIndex = Math.floor(offsetY / spacing) - STAR_RANGE_INDICES;
        yIndex <= Math.ceil((offsetY + worldHeight) / spacing)
          + STAR_RANGE_INDICES;
        yIndex++
      ) {
        var hash = cachedMD5(xIndex + ':' + yIndex + ':' + level);
        var x = xIndex * spacing
          + (hash[0] / MAX_INT) * spacing * STAR_RANGE_INDICES;
        var y = yIndex * spacing
          + (hash[1] / MAX_INT) * spacing * STAR_RANGE_INDICES;
	var z = Math.atan(
          Math.exp(-level + (hash[2] / MAX_INT)) * BRIGHTNESS_FACTOR
            / Math.exp(-levelForCurrentScale)
        ) * 2 / Math.PI;
        context.fillStyle = 'rgba(255, 255, 255, ' + z + ')';
        context.fillRect(
          (x - offsetX) * scale,
          (y - offsetY) * scale,
          STAR_SIZE_PIXELS,
          STAR_SIZE_PIXELS
        );
      }
    }
  }

  timestamps.push(new Date().getTime());
  if (timestamps.length > 10) {<commit_msg>quantize and batch calls to fillStyle<commit_after>// -- settings, immutable -- //
var BRIGHTNESS_FACTOR = 10; // Higher = brighter
var STAR_SIZE_PIXELS = 1.5;
var STAR_RANGE_INDICES = 10; // Higher = more random looking, comp expensive
var LEVEL_DEPTH = 5; // Higher = more (faint) stars, comp expensive

// TODO:
// - touchscreen support
// - resize / fullscreen
// - older browsers / polyfill

var MAX_INT = -1 >>> 1;

// -- zoom and pan, altered by listeners -- //
var offsetX = 0; // Top left has this x coordinate in world frame.
var offsetY = 0;
// scale of 1 means 1 world unit = 1 canvas pixel
// scale of 100 means 1 world unit = 100 canvas pixels
var scale = 1;

var canvas = document.getElementById("starfield");
canvas.style['background-color'] = 'black';
var context = canvas.getContext('2d');

var timestamps = [];

var cache = new RRCache(100000);
function cachedMD5(to_hash) {
  var cached = cache.get(to_hash);
  if (cached) return cached; else {
    var digest = SparkMD5.hash(to_hash, true);
    cache.set(to_hash, digest);
    return digest;
  }
}

function render() {
  var worldWidth = canvas.width / scale;
  var worldHeight = canvas.height / scale;

  // The level at which you would expect one star in current viewport.
  var levelForCurrentScale = - Math.log(worldWidth * worldHeight) / 2
  var startLevel = Math.floor(levelForCurrentScale);
  context.clearRect(0, 0, canvas.width, canvas.height);

  // setting fillStyle is expensive, so quantize and batch it.
  var brightnessToWorldPositions = [];
  for (var i = 0; i < 100; i++) brightnessToWorldPositions.push([]);

  for (level = startLevel; level < startLevel + LEVEL_DEPTH; level++) {
    var spacing = Math.exp(-level);
    for (
      xIndex = Math.floor(offsetX / spacing) - STAR_RANGE_INDICES;
      xIndex <= Math.ceil((offsetX + worldWidth) / spacing)
        + STAR_RANGE_INDICES;
      xIndex++
    ) {
      for (
        yIndex = Math.floor(offsetY / spacing) - STAR_RANGE_INDICES;
        yIndex <= Math.ceil((offsetY + worldHeight) / spacing)
          + STAR_RANGE_INDICES;
        yIndex++
      ) {
        var hash = cachedMD5(xIndex + ':' + yIndex + ':' + level);
        brightnessToWorldPositions[
          Math.floor(
	    100 * Math.atan(
              Math.exp(-level + (hash[2] / MAX_INT)) * BRIGHTNESS_FACTOR
                / Math.exp(-levelForCurrentScale)
            ) * 2 / Math.PI
          )
        ].push([
          xIndex * spacing
            + (hash[0] / MAX_INT) * spacing * STAR_RANGE_INDICES,
          yIndex * spacing
            + (hash[1] / MAX_INT) * spacing * STAR_RANGE_INDICES,
        ]);
      }
    }
  }

  for (i = 0; i < 100; i++) {
    context.fillStyle = 'rgba(255, 255, 255, ' + i / 100 + ')';
    var to_paint = brightnessToWorldPositions[i];
    for (var j = 0; j < to_paint.length; j++) {
      context.fillRect(
        (to_paint[j][0] - offsetX) * scale,
        (to_paint[j][1] - offsetY) * scale,
        STAR_SIZE_PIXELS,
        STAR_SIZE_PIXELS
      );
    }
  }

  timestamps.push(new Date().getTime());
  if (timestamps.length > 10) {
{'fraction_non_alphanumeric': 0.12960698689956332, 'fraction_numerical': 0.020436681222707424, 'mean_word_length': 2.5631611698817673, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 11, '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': '1818099', 'n_tokens_mistral': 2001, 'n_tokens_neox': 1871, 'n_words': 505}