<commit_before>canvas = document.getElementById 'canvas'
ctx = canvas.getContext '2d'

image = ctx.createImageData canvas.width, canvas.height
w = image.width
h = image.height

max_itr = 1000

palette = chroma.scale('RdYlBu')
  .domain([0, max_itr], max_itr + 1)
  .mode('lab')

mandelbrot = (px, py) ->
  x0 = px / w * 3.5 - 2.5
  y0 = py / h * 2 - 1
  x = 0
  y = 0
  itr = 0
  while x * x + y * y < (1 << 16) and itr < max_itr
    tx = x * x - y * y + x0
    y = 2 * x * y + y0
    x = tx
    itr++
  if itr < max_itr
    zn = Math.sqrt x * x + y * y
    nu = Math.log(Math.log zn / Math.log 2) / Math.log 2
    itr = itr + 1 - nu
  itr - 1

for y in [0...h]
  for x in [0...w]
    m = mandelbrot x, y
    c1 = palette Math.floor m
    c2 = palette Math.floor m + 1
    c = chroma(chroma.interpolate c1, c2, m % 1, 'lab')
    [r, g, b] = c.rgb()
    idx = (y * w + x) * 4
    image.data[idx + 0] = r
    image.data[idx + 1] = g
    image.data[idx + 2] = b
    image.data[idx + 3] = 255

ctx.putImageData image, 0, 0
<commit_msg>Linear interpolation of colors<commit_after>canvas = document.getElementById 'canvas'
ctx = canvas.getContext '2d'
image = ctx.createImageData canvas.width, canvas.height

w = image.width
h = image.height
num_pixels = w * h
max_itr = 1000

ms = new Array num_pixels
hgram = (0 for i in [0...max_itr])

palette = chroma.scale('RdYlBu')

mandelbrot = (px, py) ->
  x0 = px / w * 3.5 - 2.5
  y0 = py / h * 2 - 1
  x = 0
  y = 0
  itr = 0
  while x * x + y * y < (1 << 16) and itr < max_itr
    tx = x * x - y * y + x0
    y = 2 * x * y + y0
    x = tx
    itr++
  if itr < max_itr
    zn = Math.sqrt x * x + y * y
    nu = Math.log(Math.log zn / Math.log 2) / Math.log 2
    itr = itr + 1 - nu
  itr - 1

render = (idx) ->
  level = Math.floor ms[idx] + 1
  phue = hue = 0
  for i in [0..level]
    phue = hue
    hue += hgram[i]
  c1 = palette(phue / num_pixels)
  c2 = palette(hue / num_pixels)
  c = chroma(chroma.interpolate c1, c2, ms[idx] % 1)
  [r, g, b] = c.rgb()
  image.data[idx * 4 + 0] = r
  image.data[idx * 4 + 1] = g
  image.data[idx * 4 + 2] = b
  image.data[idx * 4 + 3] = 255

for y in [0...h]
  for x in [0...w]
    m = mandelbrot x, y
    ms[y * w + x] = m
    hgram[Math.round m]++

for i in [0...ms.length]
  render i


ctx.putImageData image, 0, 0

{'fraction_non_alphanumeric': 0.15702479338842976, 'fraction_numerical': 0.042627229230100046, 'mean_word_length': 2.034300791556728, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1033370', 'n_tokens_mistral': 1080, 'n_tokens_neox': 1019, 'n_words': 317}