-
Notifications
You must be signed in to change notification settings - Fork 1
/
userDomInteractions.js
108 lines (90 loc) · 2.89 KB
/
userDomInteractions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
var prevState;
var controlPanel = {
onControlPanelClick: function() {
$('#control-panel div').on('click', controlPanel.changeState);
},
changeState: function() {
// Don't do anything if the active panel is reclicked
if(!$(this).hasClass('active')) {
$('#control-panel div').removeClass('active');
$(this).addClass('active');
prevState = state;
state = $(this).data('state');
// If we are out of connection mode, unselect neuron
if (state !== 'connectNeurons') {
Neuron.unSelectNeuron();
}
// If we arn't in live mode anymore, clear the grid, action potentials and all neuron charges
// Call restart function on every neuron
if (state !== 'live' && prevState === 'live') {
clearScreen();
actionPotentialList = {};
Neuron.resetNeurons();
}
}
},
onNeuronTypeChange: function() {
$('#neuronType').change(controlPanel.changeNeuronType);
},
changeNeuronType: function() {
var neuronType = $(this).val();
// Hide all spans then just show the applicable ones
_.each($('#neuron-placement span'), span => $(span).hide());
neuronInfo[neuronType].inputsToShow();
},
addNeuronTypes: function() {
_.each(_.keys(neuronInfo), neuronType => {
// Make sure this field is a neuron type
if (neuronInfo[neuronType].selectName) {
$('#neuronType').append($('<option></option>').val(neuronType).html(neuronInfo[neuronType].selectName));
}
});
},
addMusicalNotes: function() {
_.times(8, octave => {
_.each(twelveTones, (tone, index) => {
$('#noteInput').append($('<option></option>').val((octave+2)*12 + index).html(tone + (octave+1)));
});
});
}
};
var exampleSelection = {
addExamples: function() {
_.each(_.keys(exampleNeuronNets), exampleKey => {
$('#exampleInput').append($('<option></option>').val(exampleKey).html(exampleKey));
});
},
onExampleChange: function() {
$('#exampleInput').change(exampleSelection.changeExample);
},
changeExample: function() {
Neuron.resetNeurons();
clearScreen();
Neuron.loadExample($(this).val());
Neuron.resizeNeuronList(neuronList, $('#sizeInput').val(), 30);
},
};
var sizeSelection = {
onSizeChange: function() {
$('#sizeInput').change(sizeSelection.changeSize);
},
changeSize: function() {
var newSize = $(this).val();
var newNeuronList = {};
var oldSize = sketchOptions.cellSize;
neuronList = Neuron.resizeNeuronList(neuronList, newSize, oldSize);
sketchOptions.cellSize = newSize;
Neuron.resetNeurons();
clearScreen();
actionPotentialList = {};
}
};
$(() => {
controlPanel.addNeuronTypes();
controlPanel.addMusicalNotes();
controlPanel.onControlPanelClick();
controlPanel.onNeuronTypeChange();
exampleSelection.addExamples();
exampleSelection.onExampleChange();
sizeSelection.onSizeChange();
});