import * as Dom from UnitJS.Dom; import Constellation; var toolbox; var tool; var colors; return { init: init, get: get, color: color, tool: tool }; function init(size, elementId) { toolbox = document.getElementById(elementId || 'toolbox'); colors = toolbox.querySelector('#colors'); for(var i = 0; i < size; i++) { colors.appendChild(Dom.make('option', {class: 'color' + i})); } colors.addEventListener('change', function() { colors.className = color(); }); tool = toolbox.querySelector('#tool'); toolbox.querySelector('#scatter').addEventListener('click', function() { var constellation = Constellation.random(size); for(var i = 0; i < size; i++) { console.log(constellation[i].map(function(x) {return x ? '*' : ' ';}).join('|')); } }); } function get() { return toolbox; } function tool() { return tool.value; } function color() { return colors.selectedIndex; }