Canvas as pointsMaterial map

Creates a dynamic canvas to make points circles. Ansers for stackoverflow question: 41509156 http://stackoverflow.com/questions/41509156/three-js-give-particles-round-form

by Chris Brown

HTML

<script src="https://cdn.rawgit.com/mrdoob/three.js/r83/build/three.min.js"></script>
<script src="https://cdn.rawgit.com/mrdoob/stats.js/r17/build/stats.min.js"></script>
<script src="https://cdn.rawgit.com/mrdoob/three.js/r83/examples/js/Detector.js"></script>
<title>three.js webgl - particles</title>

<div id="content"><b>The Aardvark-Ant Heads discuss Native Americans</b><br>
  <i>by: Seph Reed</i>
<hr>
The following is the better part of a conversation I overheard whilst at a purportedly unnoteworthy social place on one of the less advanced and habitable planets which lie in the Aardvark-Ant Head's galaxy of origin.  For anyone who doesn't know, we call them this by their choice.  Their language is not at all phonetic, and when asked what they'd like to be called, they responded "Something unambiguous.  A name which can be immediately recognized."  So what may seem offensive to us, is actually just accurate and easy to understand.
<br><br>
Moving on.
<br><br>
So, I was at a *bar*, and I must pause again to say, they don't have bars.  For the most part, they're completely and utterly different.  But they do have places they meet, so I'm calling it a *bar*.  Similarly, the guys (things) I overheard were not named Tom and Jerry, they were named by their most noteworthy differences, which happen to be based on various body parts I don't care to explain or create an English word for.  But if you see something italicized (or starred, depending on your text renderer), the reason is that that's not *really* what they said.  It's just close enough...
<br><br>
So I was at a *bar*, and while I'd been around this solar system for long enough to be recognized in some areas, this was not one of them.  Also, I had no desire to talk that day as Aardvark-Ant Head conversation is incredibly dry and accurate and wonderful for engineering, but absolutely lacking in humor other than the kind where you laugh at them for not getting what humor is.  But even that conversation had...

CSS

body {
  background-color: #135;
  margin: 0px;
  font-family:Arial;
  font-size: 16px;
  color:#EEE;
}

a {
  color:#0078ff;
}

#info {
  color: #fff;
  position: absolute;
  top: 0px; width: 100%;
  padding: 5px;
  z-index: 100;
}

#content {
  position: absolute;
  width: 70%;
  margin: 30px;
  margin-left: 15%;
  
}

JavaScript

if (!Detector.webgl) Detector.addGetWebGLMessage();

var container, stats;
var camera, scene, renderer, particles, geometry, materials = [],
  parameters, i, h, color, size;
var mouseX = 0,
  mouseY = 0;

var windowHalfX = window.innerWidth / 2;
var windowHalfY = window.innerHeight / 2;

init();
animate();

function createCanvasMaterial(color, size) {
	var matCanvas = document.createElement('canvas');
  matCanvas.width = matCanvas.height = size;
  var matContext = matCanvas.getContext('2d');
  // create exture object from canvas.
  var texture = new THREE.Texture(matCanvas);
  // Draw a circle
  var center = size / 2;
  matContext.beginPath();
  matContext.arc(center, center, size/2, 0, 2 * Math.PI, false);
  matContext.closePath();
  matContext.fillStyle = color;
  matContext.fill();
  // need to set needsUpdate
  texture.needsUpdate = true;
  // return a texture made from the canvas
  return texture;
}

function init() {

  container = document.createElement('div');
  container.style.position = "fixed";
  container.style.zIndex = -1;
  document.body.appendChild(container);

  camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 1, 2000);
  camera.position.z = 1000;

  scene = new THREE.Scene();
  scene.fog = new THREE.FogExp2(0x000000, 0.0007);

  geometry = new THREE.Geometry();
  
  //geometry = THREE.SphereGeometry( 1, 2, 2 );

  for (i = 0; i < 100; i++) {

    var vertex = new THREE.Vector3();
    vertex.x = Math.random() * 2000 - 1000;
    vertex.y = Math.random() * 2000 - 1000;
    vertex.z = Math.random() * 2000 - 1000;

    geometry.vertices.push(vertex);

  }

 parameters = [
    [
      [1, 1, 0.5], 5
    ],
    [
      [0.95, 1, 0.5], 4
    ],
    [
      [0.0, 0.0, 1.0], 3
    ],
    [
      [0.0, 1.0, 0.0], 2
    ],
    [
      [1.0, 0.0, 0.0], 1
    ]
  ];
  
 /*parameters = [
    [
      [1, 0.5, 0.9], 0.5
    ],
    [
      [0.95, 0.5, 0.9], 0.4
    ],
    [
      [0.90, 0.5, 0.9], 0.3
    ],
    [
      [0.85, 0.5,...