|
|
|
@ -1,15 +1,19 @@ |
|
|
|
|
import Rx, { Observable } from 'rxjs'; |
|
|
|
|
import { CONTROLS } from './enums'; |
|
|
|
|
|
|
|
|
|
function Controls(container, { animating, count, maxCount, speed }, customNodes) { |
|
|
|
|
function Controls(container, { animating, count, maxCount, randomizeRadius, randomizeRotation, speed }, customNodes) { |
|
|
|
|
this.nodes = { |
|
|
|
|
animating: createAnimatingControl(animating), |
|
|
|
|
count: createCountControl(count, maxCount), |
|
|
|
|
radius: createRandomRadiusControl(randomizeRadius), |
|
|
|
|
rotation: createRandomRotationControl(randomizeRotation), |
|
|
|
|
speed: createSpeedControl(speed), |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
container.appendChild(this.nodes.count); |
|
|
|
|
container.appendChild(this.nodes.speed); |
|
|
|
|
container.appendChild(this.nodes.radius); |
|
|
|
|
container.appendChild(this.nodes.rotation); |
|
|
|
|
|
|
|
|
|
if (customNodes !== undefined) { |
|
|
|
|
customNodes.forEach(node => { container.appendChild(node); }); |
|
|
|
@ -19,6 +23,8 @@ function Controls(container, { animating, count, maxCount, speed }, customNodes) |
|
|
|
|
|
|
|
|
|
this.updateOptions({ key: CONTROLS.ANIMATING, value: animating }); |
|
|
|
|
this.updateOptions({ key: CONTROLS.COUNT, value: count }); |
|
|
|
|
this.updateOptions({ key: CONTROLS.RADIUS, value: randomizeRadius }); |
|
|
|
|
this.updateOptions({ key: CONTROLS.ROTATION, value: randomizeRotation }); |
|
|
|
|
this.updateOptions({ key: CONTROLS.SPEED, value: speed }); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -40,27 +46,35 @@ Controls.prototype.updateOptions = function({ key, value}) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Controls.prototype.mount = function(customNodes) { |
|
|
|
|
const animatingStream = Rx.Observable.fromEvent(this.nodes.animating, 'change') |
|
|
|
|
const animating$ = Rx.Observable.fromEvent(this.nodes.animating, 'change') |
|
|
|
|
.map(evt => ({ key: CONTROLS.ANIMATING, value: evt.target.checked })); |
|
|
|
|
|
|
|
|
|
const countStream = Rx.Observable.fromEvent(this.nodes.count, 'input') |
|
|
|
|
const count$ = Rx.Observable.fromEvent(this.nodes.count, 'input') |
|
|
|
|
.map(evt => ({ key: CONTROLS.COUNT, value: evt.target.value * 1 })); |
|
|
|
|
|
|
|
|
|
const speedStream = Rx.Observable.fromEvent(this.nodes.speed, 'input') |
|
|
|
|
.map(evt => ({ key: CONTROLS.SPEED, value: evt.target.value * 1 })); |
|
|
|
|
const radius$ = Rx.Observable.fromEvent(this.nodes.radius, 'change') |
|
|
|
|
.map(evt => ({ key: CONTROLS.RADIUS, value: evt.target.checked })); |
|
|
|
|
|
|
|
|
|
const rotation$ = Rx.Observable.fromEvent(this.nodes.rotation, 'change') |
|
|
|
|
.map(evt => ({ key: CONTROLS.ROTATION, value: evt.target.checked })); |
|
|
|
|
|
|
|
|
|
animatingStream.subscribe(this.updateOptions.bind(this)); |
|
|
|
|
countStream.subscribe(this.updateOptions.bind(this)); |
|
|
|
|
speedStream.subscribe(this.updateOptions.bind(this)); |
|
|
|
|
const speed$ = Rx.Observable.fromEvent(this.nodes.speed, 'input') |
|
|
|
|
.map(evt => ({ key: CONTROLS.SPEED, value: evt.target.value * 1 })); |
|
|
|
|
|
|
|
|
|
return Rx.Observable.merge( |
|
|
|
|
animatingStream, |
|
|
|
|
countStream, |
|
|
|
|
speedStream, |
|
|
|
|
const eventStack$ = Rx.Observable.merge( |
|
|
|
|
animating$, |
|
|
|
|
count$, |
|
|
|
|
radius$, |
|
|
|
|
rotation$, |
|
|
|
|
speed$ |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
eventStack$.subscribe(this.updateOptions.bind(this)); |
|
|
|
|
|
|
|
|
|
return eventStack$; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const createAnimatingControl = function(value) { |
|
|
|
|
function createAnimatingControl(value) { |
|
|
|
|
const label = document.createElement('label'); |
|
|
|
|
label.className = 'controls-label'; |
|
|
|
|
label.className = 'controls-animating'; |
|
|
|
@ -78,7 +92,7 @@ const createAnimatingControl = function(value) { |
|
|
|
|
return label; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const createCountControl = function(value, max) { |
|
|
|
|
function createCountControl(value, max) { |
|
|
|
|
const label = document.createElement('label'); |
|
|
|
|
label.className = 'controls-range'; |
|
|
|
|
|
|
|
|
@ -99,6 +113,45 @@ const createCountControl = function(value, max) { |
|
|
|
|
return label; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function createRandomRadiusControl(value) { |
|
|
|
|
const label = document.createElement('label'); |
|
|
|
|
label.className = 'controls-checkbox'; |
|
|
|
|
|
|
|
|
|
const text = document.createElement('span'); |
|
|
|
|
text.innerHTML = 'Random radii'; |
|
|
|
|
text.className = 'controls-checkbox-text'; |
|
|
|
|
|
|
|
|
|
const checkbox = document.createElement('input'); |
|
|
|
|
checkbox.type = 'checkbox'; |
|
|
|
|
checkbox.className = 'controls-checkbox-input'; |
|
|
|
|
checkbox.checked = value; |
|
|
|
|
|
|
|
|
|
label.appendChild(checkbox); |
|
|
|
|
label.appendChild(text); |
|
|
|
|
|
|
|
|
|
return label; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function createRandomRotationControl(value) { |
|
|
|
|
const label = document.createElement('label'); |
|
|
|
|
label.className = 'controls-checkbox'; |
|
|
|
|
|
|
|
|
|
const text = document.createElement('span'); |
|
|
|
|
text.innerHTML = 'Random rotation'; |
|
|
|
|
text.className = 'controls-checkbox-text'; |
|
|
|
|
|
|
|
|
|
const checkbox = document.createElement('input'); |
|
|
|
|
checkbox.type = 'checkbox'; |
|
|
|
|
checkbox.className = 'controls-checkbox-input'; |
|
|
|
|
checkbox.checked = value; |
|
|
|
|
|
|
|
|
|
label.appendChild(checkbox); |
|
|
|
|
label.appendChild(text); |
|
|
|
|
|
|
|
|
|
return label; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const createSpeedControl = function(value) { |
|
|
|
|
const label = document.createElement('label'); |
|
|
|
|
label.className = 'controls-range'; |
|
|
|
|