modified from http://jsfiddle.net/justin_c_rounds/Gd2S2/light/
7658
function lineIntersects(line1StartX, line1StartY, line1EndX, line1EndY, line2StartX, line2StartY, line2EndX, line2EndY) {
  // if the lines intersect, the result contains the x and y of the intersection (treating the lines as infinite) and booleans for whether line segment 1 or line segment 2 contain the point
  var denominator, a, b, numerator1, numerator2,
    result = {
      x: null,
      y: null,
      onLine1: false,
      onLine2: false
    };
  denominator = ((line2EndY - line2StartY) * (line1EndX - line1StartX)) - ((line2EndX - line2StartX) * (line1EndY - line1StartY));
  if (denominator === 0) {
    if (result.x !== null && result.y !== null) {
      return result;
    } else {
      return false;
    }
  }
  a = line1StartY - line2StartY;
  b = line1StartX - line2StartX;
  numerator1 = ((line2EndX - line2StartX) * a) - ((line2EndY - line2StartY) * b);
  numerator2 = ((line1EndX - line1StartX) * a) - ((line1EndY - line1StartY) * b);
  a = numerator1 / denominator;
  b = numerator2 / denominator;

  // if we cast these lines infinitely in both directions, they intersect here:
  result.x = line1StartX + (a * (line1EndX - line1StartX));
  result.y = line1StartY + (a * (line1EndY - line1StartY));

  // if line1 is a segment and line2 is infinite, they intersect if:
  if (a > 0 && a < 1) {
    result.onLine1 = true;
  }
  // if line2 is a segment and line1 is infinite, they intersect if:
  if (b > 0 && b < 1) {
    result.onLine2 = true;
  }
  // if line1 and line2 are segments, they intersect if both of the above are true
  if (result.onLine1 && result.onLine2) {
    return [result.x, result.y];
  } else {
    return false;
  }
}
994139
function isDark (r, g, b) {
  /**
   * W3C perceived brightness calculator
   * @see {@link https://www.w3.org/TR/AERT/#color-contrast}
   */
  const brightness = ((r * 299) + (g * 587) + (b * 114)) / 1000

  if (brightness < 140) {
    return true
  }

  return false
}
187352
function (x, y, width, height, dpr) {
        this._gBuffer.setViewport(x, y, width, height, dpr);
        this._lightAccumFrameBuffer.viewport = this._gBuffer.getViewport();
    }
109165
function hslToRgb(h, s, l) {

  h /= 360;
  s /= 100;
  l /= 100;

  var r, g, b;

  if (s === 0) {
    r = g = b = l; // achromatic
  } else {
    var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
    var p = 2 * l - q;
    r = hueToRgb(p, q, h + 1 / 3);
    g = hueToRgb(p, q, h);
    b = hueToRgb(p, q, h - 1 / 3);
  }

  return ({
    r: r * 255,
    g: g * 255,
    b: b * 255
  });
}
624712
function ( type, settings, parent, colors ) {

        T.dom( type, null, settings, parent, 0 );

        var n = parent.childNodes[0].childNodes.length - 1, c;

        for( var i = 0; i < colors.length; i++ ){

            c = colors[i];
            T.dom( 'stop', null, { offset:c[0]+'%', style:'stop-color:'+c[1]+'; stop-opacity:'+c[2]+';' }, parent, [0,n] );

        }

    }
88172
function (domElt, color) {
            this.clearHightlight();
            color = color ? color : "#ACC2FF";
            var pos = this.bridge.getAriaPackage().utils.Dom.calculatePosition(domElt);
            var marker = this.bridge.getDocument().createElement('div');
            marker.style.cssText = ["position:absolute;top:", pos.top, "px;left:", pos.left, "px;width:",
                    ((domElt.offsetWidth - 8 > 0) ? domElt.offsetWidth - 8 : 0), "px;height:",
                    ((domElt.offsetHeight - 8 > 0) ? domElt.offsetHeight - 8 : 0),
                    "px; border:dashed 4px " + color + ";z-index: 999999999999999;z-index: 999999999999999;"].join('');
            this._holder.appendChild(marker);
            marker = null;
            this._hideTimeout = setTimeout(aria.utils.Function.bind(this.clearHightlight, this), 2000);
        }
1311336
function(svg) {
		"use strict";

		var parent = this;
		var options = parent.options;

		if (arguments.length === 0) {
			svg = parent.root.selectAll(".graph-domain");
		}

		var rect = svg
			.selectAll("svg").selectAll("g")
			.data(function(d) { return parent._domains.get(d); })
		;

		/**
		 * Colorize the cell via a style attribute if enabled
		 */
		function addStyle(element) {
			if (parent.legendScale === null) {
				return false;
			}

			element.attr("fill", function(d) {
				if (d.v === null && (options.hasOwnProperty("considerMissingDataAsZero") && !options.considerMissingDataAsZero)) {
					if (options.legendColors.hasOwnProperty("base")) {
						return options.legendColors.base;
					}
				}

				if (options.legendColors !== null && options.legendColors.hasOwnProperty("empty") &&
					(d.v === 0 || (d.v === null && options.hasOwnProperty("considerMissingDataAsZero") && options.considerMissingDataAsZero))
				) {
					return options.legendColors.empty;
				}

				if (d.v < 0 && options.legend[0] > 0 && options.legendColors !== null && options.legendColors.hasOwnProperty("overflow")) {
					return options.legendColors.overflow;
				}

				return parent.legendScale(Math.min(d.v, options.legend[options.legend.length-1]));
			});
		}

		rect.transition().duration(options.animationDuration).select("rect")
			.attr("class", function(d) {

				var htmlClass = parent.getHighlightClassName(d.t).trim().split(" ");
				var pastDate = parent.dateIsLessThan(d.t, new Date());
        var sameDate = parent.dateIsEqual(d.t, new Date());

				if (parent.legendScale === null ||
					(d.v === null && (options.hasOwnProperty("considerMissingDataAsZero") && !options.considerMissingDataAsZero) &&!options.legendColors.hasOwnProperty("base"))
				) {
					htmlClass.push("graph-rect");
				}

        if (sameDate) {
          htmlClass.push("now");
        } else if (!pastDate) {
          htmlClass.push("future");
        }

				if (d.v !== null) {
					htmlClass.push(parent.Legend.getClass(d.v, (parent.legendScale === null)));
				} else if (options.considerMissingDataAsZero && pastDate) {
					htmlClass.push(parent.Legend.getClass(0, (parent.legendScale === null)));
				}

				if (options.onClick !== null) {
					htmlClass.push("hover_cursor");
				}

				return htmlClass.join(" ");
			})
			.call(addStyle)
		;

		rect.transition().duration(options.animationDuration).select("title")
			.text(function(d) { return parent.getSubDomainTitle(d); })
		;

		function formatSubDomainText(element) {
			if (typeof options.subDomainTextFormat === "function") {
				element.text(function(d) { return options.subDomainTextFormat(d.t, d.v); });
			}
		}

		/**
		 * Change the subDomainText class if necessary
		 * Also change the text, e.g when text is representing the value
		 * instead of the date
		 */
		rect.transition().duration(options.animationDuration).select("text")
			.attr("class", function(d) { return "subdomain-text" + parent.getHighlightClassName(d.t); })
			.call(formatSubDomainText)
		;
	}
981661
def SetHighlight( self, node, point=None, propagate=True ):
        """"""
        if node == self.highlightedNode:
            return
        self.highlightedNode = node
        # TODO: restrict refresh to the squares for previous node and new node...
        self.UpdateDrawing()
        if node and propagate:
            wx.PostEvent( self, SquareHighlightEvent( node=node, point=point, map=self ) )
882552
function lightenColor(col, amount) {
  let colRgba = parseColor(col);
  let colHsla = rgbaToHsla(colRgba.r, colRgba.g, colRgba.b, colRgba.a);
  colRgba = hslaToRgba(colHsla[0],colHsla[1],Math.min(Math.max(colHsla[2]+amount, 0), 1),colHsla[3]);
  return RGBobj2string({
    r: colRgba[0],
    g: colRgba[1],
    b: colRgba[2],
    a: colRgba[3]
  });
}
1181801
def update_virtual_light(light, cascade)
      virtual_light = light.shadow_cascade_array[cascade]

      virtual_light.position.copy(light.position)
      virtual_light.target.position.copy(light.target.position)
      virtual_light.look_at(virtual_light.target)

      virtual_light.shadow_camera_visible = light.shadow_camera_visible
      virtual_light.shadow_darkness = light.shadow_darkness

      virtual_light.shadow_bias = light.shadow_cascade_bias[cascade]

      near_z = light.shadow_cascade_near_z[cascade]
      far_z = light.shadow_cascade_far_z[cascade]

      points_frustum = virtual_light.points_frustum

      points_frustum[0].z = near_z
      points_frustum[1].z = near_z
      points_frustum[2].z = near_z
      points_frustum[3].z = near_z

      points_frustum[4].z = far_z
      points_frustum[5].z = far_z
      points_frustum[6].z = far_z
      points_frustum[7].z = far_z
    end
970120
public void setAmbientLight(float r, float g, float b, float x, float y,
            float z) {
        float ambient[] = { r, g, b, 255 };
        float position[] = { x, y, z, 1.0f };
        normalize(ambient);
        gl.glEnable(GL2.GL_LIGHTING);
        gl.glEnable(GL2.GL_LIGHT0);
        gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_POSITION, position, 0);
        gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_AMBIENT, ambient, 0);
    }
574125
function adjustLuminance(rgb, lum) {
  var newRgb = {};
  newRgb.red = calculateLuminance(rgb.red, lum);
  newRgb.green = calculateLuminance(rgb.green, lum);
  newRgb.blue = calculateLuminance(rgb.blue, lum);

  return newRgb;
}
113141
function click(d) {
      if (!d.children) {
        // check selected
        context.queryLib.addAnnotationTag(d.text);
        return;
      }

      kx = (d.y ? w - 40 : w) / (1 - d.y);
      ky = h / d.dx;
      x.domain([d.y, 1]).range([d.y ? 40 : 0, w]);
      y.domain([d.x, d.x + d.dx]);

      var t = g.transition()
          .duration(d3.event.altKey ? 7500 : 750)
          .attr("transform", function(d) { return "translate(" + x(d.y) + "," + y(d.x) + ")"; });

      t.select("rect")
          .attr("width", d.dy * kx)
          .attr("height", function(d) { return d.dx * ky; });

      t.select("text")
          .attr("transform", transform)
          .style("opacity", function(d) { return d.dx * ky > 12 ? 1 : 0; });

      d3.event.stopPropagation();
    }
46644
function DirectionalLight(name, direction, scene) {
            var _this = _super.call(this, name, scene) || this;
            _this._shadowFrustumSize = 0;
            _this._shadowOrthoScale = 0.5;
            _this.autoUpdateExtends = true;
            // Cache
            _this._orthoLeft = Number.MAX_VALUE;
            _this._orthoRight = Number.MIN_VALUE;
            _this._orthoTop = Number.MIN_VALUE;
            _this._orthoBottom = Number.MAX_VALUE;
            _this.position = direction.scale(-1.0);
            _this.direction = direction;
            return _this;
        }
597937
function init() {
  var root = new THREERoot();
  root.renderer.setClearColor(0x000000);
  root.camera.position.set(12, 12, 0);

  var light = new THREE.DirectionalLight(0xffffff, 1.0);
  light.position.set(0, 1, 0);
  root.add(light);
  root.addUpdateCallback(function() {
    light.position.copy(root.camera.position).normalize();
  });

  var pointLight = new THREE.PointLight();
  pointLight.position.set(0, 10, 0);
  root.add(pointLight);

  var gridHelper, animation, tween;

  // html stuff
  var elCount = document.querySelector('.count');
  var elBtnLeft = document.querySelector('.btn.left');
  var elBtnRight = document.querySelector('.btn.right');

  var sizes = [1, 2, 5, 10, 20, 50, 100, 200, 500, 1000];
  var index = 0;

  function createAnimation(i) {
    var gridSize = sizes[i];

    elCount.innerHTML = gridSize;
    elBtnRight.classList.toggle('disabled', i === sizes.length - 1);
    elBtnLeft.classList.toggle('disabled', index === 0);

    if (gridHelper) {
      root.remove(gridHelper);
      gridHelper.material.dispose();
      gridHelper.geometry.dispose();
    }

    if (animation) {
      root.remove(animation);
      animation.material.dispose();
      animation.geometry.dispose();
    }

    gridHelper = new THREE.GridHelper(gridSize * 0.5, 1, 0x222222, 0x444444);
    root.add(gridHelper);

    animation = new Animation(gridSize);
    root.add(animation);

    tween = animation.animate({repeat:-1, repeatDelay: 0.0, ease:Power0.easeNone}).timeScale(2.0);
  }

  elBtnLeft.addEventListener('click', function() {
    index = Math.max(0, index - 1);
    createAnimation(index);
  });
  elBtnRight.addEventListener('click', function() {
    index = Math.min(index + 1, sizes.length - 1);
    createAnimation(index);
  });

  createAnimation(index);
}
293934
public void setLightAttenuation(int i, float constant, float liner, float quadratic) {
		float c[] = { constant };
		float l[] = { liner };
		float q[] = { quadratic };
		gl.glEnable(GL2.GL_LIGHTING);
		gl.glEnable(GL2.GL_LIGHT0 + i);
		gl.glLightfv(GL2.GL_LIGHT0 + i, GL2.GL_CONSTANT_ATTENUATION, c, 0);
		gl.glLightfv(GL2.GL_LIGHT0 + i, GL2.GL_LINEAR_ATTENUATION, l, 0);
		gl.glLightfv(GL2.GL_LIGHT0 + i, GL2.GL_QUADRATIC_ATTENUATION, q, 0);
	}
986329
function () {
    let light = new THREE.PointLight(0xffffff, 1, c.SUN_RADIUS * 5);
    light.position.y = c.SUN_RADIUS * 4;
    return light;
  }