<commit_before>var _ = require('lodash')
var inherits = require('inherits')
var color = require('d3-color')
var notch = require('./geo/notch.js')
var cap = require('./geo/cap.js')
var Entity = require('crtrdg-entity')

module.exports = Ring;
inherits(Ring, Entity);

function Ring(opts){

  var fill = opts.fill
  var offset = opts.offset || 0
  var count = opts.count || 6
  var extent = opts.extent || 20
  var size = opts.size || 50
  var position = opts.position || [size/2, size/2]

  var notches = _.flatten(_.range(6).map(function (side) {
    return _.range(1, count-1).map(function (ind) {
      return notch({
        size: size, 
        extent: extent, 
        ind: ind, 
        count: count, 
        offset: offset, 
        angle: (side * 60) + 30,
        position: position
      })
    })
  }))

  var caps = _.range(6).map(function (side) {
    return cap({
      size: size,
      extent: extent,
      count: count,
      offset: offset,
      angle: (side * 60) + 30,
      position: position
    })
  })

  _.range(6).forEach(function(i) {
    notches.splice(i*(opts.count-1), 0, caps[i])
  })

  this.notches = notches
}

Ring.prototype.draw = function(context) {
  this.notches.forEach( function(notch) {
    notch.draw(context)
  })
}

Ring.prototype.recolor = function(colors) {
  this.notches.forEach(function(notch, i) {
    notch.props.fill = colors[i]
  })
}

Ring.prototype.project = function(origin, targets) {
  return targets.map(function (target) {
    var diff = origin.difference(target)
    var dist = origin.distance(target)

    var radius = dist.position / 100
    var angle = Math.atan2(-diff.position[1], -diff.position[0]) * 180 / Math.PI

    if (angle < 0) angle += 360
    angle = angle - 90
    if (angle < 0) angle += 360

    var offset = -origin.angle() % 360
    if (offset < 0) offset += 360
    offset = 360 - offset
    if (offset == 360) offset = 0

    angle -= offset
    if (angle < 0) angle += 360

    var interp = Math.max(1 - radius, 0.5)
    var fill = color.interpolateHsl('rgb(55,55,55)', target.color)(interp)
    
    if (radius < .01) angle = 0

    return {angle: angle, radius: radius, fill: fill}
  })
}

Ring.prototype.update = function(player, world) {
  self = this

  var maxangle = 110

  var projections = this.project(player.geometry.transform, world.cues())

  function discretize(i, p, length) {
    var tmp = p.angle - i * 360.0/length
    if (tmp > 180) tmp = 360 - tmp
    if (tmp < -180) tmp = 360 + tmp
    
    if (Math.abs(tmp) <= Math.min(40/p.radius * (Math.sqrt(3)/2)/2, maxangle)/2 & p.radius < 1) {<commit_msg>make scale, maxdistance, maxangle, parameters<commit_after>var _ = require('lodash')
var inherits = require('inherits')
var color = require('d3-color')
var notch = require('./geo/notch.js')
var cap = require('./geo/cap.js')
var Entity = require('crtrdg-entity')

module.exports = Ring;
inherits(Ring, Entity);

function Ring(opts){

  var fill = opts.fill
  var offset = opts.offset || 0
  var count = opts.count || 6
  var extent = opts.extent || 20
  var size = opts.size || 50
  var position = opts.position || [size/2, size/2]
  
  this.maxangle = opts.maxangle || 110
  this.maxdistance = opts.maxdistance || 100
  this.scale = opts.scale || 20

  var notches = _.flatten(_.range(6).map(function (side) {
    return _.range(1, count-1).map(function (ind) {
      return notch({
        size: size, 
        extent: extent, 
        ind: ind, 
        count: count, 
        offset: offset, 
        angle: (side * 60) + 30,
        position: position
      })
    })
  }))

  var caps = _.range(6).map(function (side) {
    return cap({
      size: size,
      extent: extent,
      count: count,
      offset: offset,
      angle: (side * 60) + 30,
      position: position
    })
  })

  _.range(6).forEach(function(i) {
    notches.splice(i*(opts.count-1), 0, caps[i])
  })

  this.notches = notches
}

Ring.prototype.draw = function(context) {
  this.notches.forEach( function(notch) {
    notch.draw(context)
  })
}

Ring.prototype.recolor = function(colors) {
  this.notches.forEach(function(notch, i) {
    notch.props.fill = colors[i]
  })
}

Ring.prototype.project = function(origin, targets) {
  self = this

  return targets.map(function (target) {
    var diff = origin.difference(target)
    var dist = origin.distance(target)

    var radius = dist.position / self.maxdistance
    var angle = Math.atan2(-diff.position[1], -diff.position[0]) * 180 / Math.PI

    if (angle < 0) angle += 360
    angle = angle - 90
    if (angle < 0) angle += 360

    var offset = -origin.angle() % 360
    if (offset < 0) offset += 360
    offset = 360 - offset
    if (offset == 360) offset = 0

    angle -= offset
    if (angle < 0) angle += 360

    var interp = Math.max(1 - radius, 0.5)
    var fill = color.interpolateHsl('rgb(55,55,55)', target.color)(interp)
    
    if (radius < .01) angle = 0

    return {angle: angle, radius: radius, fill: fill}
  })
}

Ring.prototype.update = function(player, world) {
  self = this

  var projections = this.project(player.geometry.transform, world.cues())

  function discretize(i, p, length) {
    var tmp = p.angle - i * 360.0/length
    if (tmp > 180) tmp = 360 - tmp
    if (tmp < -180) tmp = 360 + tmp
    
    if (Math.abs(tmp) <= Math.min(self.scale/p.radius, self.maxangle)/2 & p.radius < 1) {
{'fraction_non_alphanumeric': 0.15165081141578063, 'fraction_numerical': 0.03637381085618355, 'mean_word_length': 2.6525885558583107, 'pattern_counts': {'":': 0, '<': 19, '<?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': '5666731', 'n_tokens_mistral': 2014, 'n_tokens_neox': 1806, 'n_words': 471}