Jarvis-Like Neural Net For Mirror
by Cory Hughes
HTML
<script src="https://cdn.rawgit.com/mrdoob/three.js/master/build/three.min.js"></script>
<div id="neuralnet" style=' height:250px; width:250px;'></div>
CSS
body {
color: #ffffff;
background-color: #000;
margin: 0px;
overflow: hidden;
}
JavaScript
var camera, scene, renderer;
var mesh, geometry, material, pointNum;
var pointIn = setInterval(setPoint, 3000);
var pointOut = setTimeout(cull, 13000);
var countPoints = "100";
var pointsUsed = [];
var scene3d = document.getElementById("neuralnet");
/* var CANVAS_WIDTH = scene3d.offsetWidth;
var CANVAS_HEIGHT = scene3d.offsetHeight; */
var CANVAS_WIDTH = 250;
var CANVAS_HEIGHT = 250;
function cull() {
console.log("Culling!")
setInterval(revertPoint, 3000);
}
init();
animate();
function init() {
camera = new THREE.PerspectiveCamera(75, CANVAS_WIDTH / CANVAS_HEIGHT, 1, 10000);
camera.position.z = 175;
scene = new THREE.Scene();
renderer = new THREE.WebGLRenderer({ alpha: true });
renderer.setSize(CANVAS_WIDTH, CANVAS_HEIGHT);
scene3d.appendChild(renderer.domElement);
addPointsCloud(4);
console.log(countPoints)
}
function animate() {
requestAnimationFrame(animate);
mesh.rotation.x += 0.003;
mesh.rotation.y += 0.001;
mesh.rotation.z += 0.002;
renderer.render(scene, camera);
}
function addPointsCloud(detailsLevel) {
geometry = new THREE.IcosahedronGeometry(102, detailsLevel);
var colors = [];
geometry.vertices.forEach(function(){
colors.push(new THREE.Color(0x333333));
});
countPoints = geometry.vertices;
console.log(countPoints.length);
geometry.colors = colors;
material = new THREE.PointsMaterial( { size:2, vertexColors: THREE.VertexColors} );
mesh = new THREE.Points(geometry, material);
scene.add(mesh);
}
function getRandomInt(pointNum) {
return Math.floor(Math.random() * Math.floor(pointNum));
}
function setPoint() {
pointNum = getRandomInt(countPoints.length);
pointsUsed.push(pointNum);
console.log("pointNum: "+pointNum);
console.log("pointsUsed: "+pointsUsed);
setTimeout((function () {revertPoint},2000));
mesh.geometry.colors[pointNum].set(0xffffff);
mesh.geometry.colorsNeedUpdate = true;
}
function revertPoint() {
var revert = pointsUsed[0];
...