<commit_before>import { getCurrentShader, getShaderConfig, getShaderViewport } from 'reducers'
import { SHADER_ENUM } from 'javascript/config'
import setUniformValue from 'webgl-utilities/setUniformValue'
import msaaCoordinates from 'webgl-utilities/msaaCoordinates'

import assign from 'lodash/assign'
import forEach from 'lodash/forEach'

const { requestAnimationFrame } = window

let time = 0 // Date.now() & Math.pow(2, 21) - 1;
export default ({ canvas, context, shader, program, store }) => function renderFrame () {
  /* eslint-disable no-multi-spaces, key-spacing */
  const state = store.getState()

  const currentShader = getCurrentShader(state)
  if (shader === currentShader) {
    const { center, range } = getShaderViewport(state, currentShader)
    const config            = getShaderConfig(state, currentShader)

    if (config.speed) {
      time += parseFloat(config.speed)
    } else {
      time += 0.016
    }

    const uniformValues = assign({}, config, {
      shader: SHADER_ENUM[currentShader],
      center: [center.x, center.y],
      range:  [range.x, range.y],
      resolution: [
        window.innerWidth,
        window.innerHeight
      ],
      julia_c: [
        -0.795 + Math.sin(time / 2000) / 40,
        0.2321 + Math.cos(time / 1330) / 40
      ],
      msaa_coordinates: msaaCoordinates[config.supersamples],
      time: time
    })

    context.useProgram(program)
    forEach(uniformValues, (uniformValue, uniformName) => {
      setUniformValue(uniformName, uniformValue, context, program)
    })

    context.drawArrays(context.TRIANGLE_STRIP, 0, 4)

    resize({ canvas, context })

    requestAnimationFrame(renderFrame)
  }
  /* eslint-enable no-multi-spaces, key-spacing */
}

function resize ({ canvas, context }) {
  /* http://webglfundamentals.org/webgl/lessons/webgl-resizing-the-canvas.html */
  const WIDTH = window.innerWidth
  const HEIGHT = window.innerHeight

  if (canvas.width !== WIDTH || canvas.height !== HEIGHT) {
    canvas.width = WIDTH<commit_msg>restores Date.now() start time rather than 0 start time<commit_after>import { getCurrentShader, getShaderConfig, getShaderViewport } from 'reducers'
import { SHADER_ENUM } from 'javascript/config'
import setUniformValue from 'webgl-utilities/setUniformValue'
import msaaCoordinates from 'webgl-utilities/msaaCoordinates'

import assign from 'lodash/assign'
import forEach from 'lodash/forEach'

const { requestAnimationFrame } = window

let time = Date.now()
export default ({ canvas, context, shader, program, store, startTime = Date.now() }) => function renderFrame () {
  /* eslint-disable no-multi-spaces, key-spacing */
  const state = store.getState()

  const currentShader = getCurrentShader(state)
  if (shader === currentShader) {
    const { center, range } = getShaderViewport(state, currentShader)
    const config            = getShaderConfig(state, currentShader)

    if (config.speed) {
      time += parseFloat(config.speed)
    } else {
      time += 0.016
    }

    const uniformValues = assign({}, config, {
      shader: SHADER_ENUM[currentShader],
      center: [center.x, center.y],
      range:  [range.x, range.y],
      resolution: [
        window.innerWidth,
        window.innerHeight
      ],
      julia_c: [
        -0.795 + Math.sin(time / 2000) / 40,
        0.2321 + Math.cos(time / 1330) / 40
      ],
      msaa_coordinates: msaaCoordinates[config.supersamples],
      time: time - startTime // large times won't convert to float 32 well
    })

    context.useProgram(program)
    forEach(uniformValues, (uniformValue, uniformName) => {
      setUniformValue(uniformName, uniformValue, context, program)
    })

    context.drawArrays(context.TRIANGLE_STRIP, 0, 4)

    resize({ canvas, context })

    requestAnimationFrame(renderFrame)
  }
  /* eslint-enable no-multi-spaces, key-spacing */
}

function resize ({ canvas, context }) {
  /* http://webglfundamentals.org/webgl/lessons/webgl-resizing-the-canvas.html */
  const WIDTH = window.innerWidth
  const HEIGHT = window.innerHeight

  if (canvas.width !== WIDTH || canvas.height !== HEIGHT) {
    canvas.width = WIDTH
{'fraction_non_alphanumeric': 0.12033898305084746, 'fraction_numerical': 0.015012106537530266, 'mean_word_length': 3.32565445026178, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '917743', 'n_tokens_mistral': 1338, 'n_tokens_neox': 1255, 'n_words': 288}