Constellations/js/Toolbox.js

44 lines
900 B
JavaScript
Raw Permalink Normal View History

2022-07-24 11:20:22 +02:00
import * as Dom from UnitJS.Dom;
import Constellation;
2022-07-24 11:20:22 +02:00
2022-07-26 19:39:06 +02:00
var toolbox;
var tool;
var colors;
2022-07-24 11:20:22 +02:00
return {
init: init,
get: get,
color: color,
tool: tool
2022-07-24 11:20:22 +02:00
};
function init(size, elementId) {
2022-07-26 19:39:06 +02:00
toolbox = document.getElementById(elementId || 'toolbox');
colors = toolbox.querySelector('#colors');
for(var i = 0; i < size; i++) {
colors.appendChild(Dom.make('option', {class: 'color' + i}));
2022-07-24 11:20:22 +02:00
}
colors.addEventListener('change', function() {
colors.className = color();
2022-07-24 11:20:22 +02:00
});
2022-07-26 19:39:06 +02:00
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('|'));
}
});
2022-07-24 11:20:22 +02:00
}
function get() {
return toolbox;
}
function tool() {
return tool.value;
2022-07-24 11:20:22 +02:00
}
function color() {
return colors.selectedIndex;
2022-07-24 11:20:22 +02:00
}