Photo of Mr Freddy Wordingham

Mr Freddy Wordingham

EEGSim

body{ background-color: ivory; } #networkCanvas{border:1px solid black;} #EEGCanvas{border:1px solid black;} New Detector
Select Detector
Move Detector
// == Sim Properties == // -- Network -- var maxConnections = 2 var maxStrength = 1.0; var nodeRadius = 10.0; var lagMultiplier = 2.0; // -- EEG -- var recordLength = 500; var refreshWait = 10; var runDuration = 100000; var maxNewWaves = 5; var noiseAmp = 2.0; var signalProb = 3000.0; // == Objects == // -- Network -- var node = []; var sensor = []; function getRandom(min,max){ // Generates a random number between min (inclusive) and max (exclusive). return ((Math.random()*(max-min))+min); } function randomColor(){ // Create a random hex colour string and return it. return('#'+Math.floor(Math.random()*16777215).toString(16)); } function interval(func, wait, times){ var interv = function(w, t){ return function(){ if(typeof t === "undefined" || t-- > 0){ setTimeout(interv, w); try{ func.call(); } catch(e){ t = 0; throw e.toString(); } } }; }(wait, times); setTimeout(interv, wait); } function drawConnection(thisCTX, x1, y1, x2, y2, width){ // Draw a line on thisCTX canvas from (x1,y1) to (x2,y2) with width. thisCTX.lineWidth = width; var grad = thisCTX.createLinearGradient(x1,y1,x2,y2); grad.addColorStop(0,'rgba(0,0,0,1)'); grad.addColorStop(1,'rgba(0,0,0,0)'); thisCTX.strokeStyle = grad; thisCTX.beginPath(); thisCTX.moveTo(x1,y1); thisCTX.lineTo(x2,y2); thisCTX.stroke(); return; } function drawLine(thisCTX, x1, y1, x2, y2, colour){ // Draw a line on thisCTX canvas from (x1,y1) to (x2,y2) with width. thisCTX.lineWidth = 1; thisCTX.strokeStyle = colour; thisCTX.beginPath(); thisCTX.moveTo(x1,y1); thisCTX.lineTo(x2,y2); thisCTX.stroke(); return; } function drawCircle(thisCTX, x, y, r, colour){ // Draw a circle of radius r at (x,y) with colour. thisCTX.beginPath(); thisCTX.arc(x,y,r,0,Math.PI*2); thisCTX.closePath(); thisCTX.fillStyle = colour; thisCTX.fill(); return; } $(function(){ // == Global Variables == // -- HTML Variables -- var $create = $('#rCreate')[0]; var $select = $('#rSelect')[0]; var $move = $('#rMove')[0]; // -- Canvas Variables -- var networkCanvas = document.getElementById('networkCanvas'); var networkCTX = networkCanvas.getContext('2d'); var $networkCanvas= $('#networkCanvas'); var networkCanvasOffset = $networkCanvas.offset(); var offsetX = networkCanvasOffset.left; var offsetY = networkCanvasOffset.top; var scrollX = $networkCanvas.scrollLeft(); var scrollY = $networkCanvas.scrollTop(); // -- Network Variables -- var selectedNode = -1; // == Functions == // -- Node Manipulation -- function handleMouseClick(mouse){ // Handel a mouse click on the network canvas. mouse.preventDefault(); mouseX = parseInt(mouse.clientX - offsetX); mouseY = parseInt(mouse.clientY - offsetY); if ($create.checked){ createNode(mouseX,mouseY); } if ($select.checked){ selectNode(mouseX,mouseY); } if ($move.checked){ moveNode(mouseX,mouseY); } createConnections(); drawDetectors(); return; } function createNode(mouseX,mouseY){ // Create a node at the given location. index = node.length; node.push({ colour: randomColor(), pos:{x:mouseX,y:mouseY}, connectionStrength:[], connectionLag: [] }); selectedNode = index; return; } function selectNode(mouseX,mouseY){ // Selects the node at the mouse location. selectedNode = -1; for (var i=0; i