summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2018-02-25 16:39:33 +0100
committerJules Laplace <julescarbon@gmail.com>2018-02-25 16:39:33 +0100
commite54f99287a24fccae52ffdee1e55c6213bf6e9b6 (patch)
tree1d24d97ccf7b087a1282209905e800851bd66014 /client
parentc1888a0cd8279f78c094947eee9a10f2137a4587 (diff)
keyboard shortcuts
Diffstat (limited to 'client')
-rw-r--r--client/index.js96
1 files changed, 91 insertions, 5 deletions
diff --git a/client/index.js b/client/index.js
index a4d5558..82be8e0 100644
--- a/client/index.js
+++ b/client/index.js
@@ -6,16 +6,12 @@ import organ from './lib/organ'
import { browser, requestAudioContext } from './lib/util'
let instrument = kalimba
-let hash = window.location.hash || window.location.search
-if (hash.match('sin') || hash.match('organ')) {
- instrument = organ
-}
const root = 440
const s = 50
const w = window.innerWidth
const h = window.innerHeight
-const ws = w/s, hs = h/s
+const ws = Math.ceil(w/s), hs = Math.ceil(h/s)
const add_on = 0
const mul_on = 1.0
@@ -59,6 +55,66 @@ function assign(freq, state) {
function toggle(freq) {
assign(freq, freq.playing = !freq.playing)
}
+function glider() {
+ const x = Math.floor(Math.random() * ws)
+ const y = Math.floor(Math.random() * hs)
+ console.log("glider at", x, y)
+ const gliderShape = [
+ [0,0,0,0,0],
+ [0,1,1,1,0],
+ [0,0,0,1,0],
+ [0,0,1,0,0],
+ [0,0,0,0,0],
+ ]
+ weave(x,y,gliderShape)
+}
+function weave (x,y,shape) {
+ const xmag = shape.length
+ const ymag = shape[0].length
+ let i, j, px, py
+ for (i = 0; i < xmag; i++) {
+ for (j = 0; j < ymag; j++) {
+ px = (x+i) % ws
+ py = (y+j) % hs
+ assign(notes[px][py], shape[i][j])
+ }
+ }
+}
+function forEach(f){
+ let i, j, note, s;
+ for (i = 0; i < ws; i++) {
+ for (j = 0; j < hs; j++) {
+ note = notes[i][j]
+ s = f(i,j,note.playing)
+ assign(note, s)
+ }
+ }
+}
+function clear(){
+ forEach((x,y,state) => {
+ return false
+ })
+}
+function white(){
+ forEach((x,y,state) => {
+ return false
+ })
+}
+function stripex(){
+ forEach((x,y,state) => {
+ return x % 2
+ })
+}
+function stripey(){
+ forEach((x,y,state) => {
+ return y % 2
+ })
+}
+function noise(){
+ forEach((x,y,state) => {
+ return Math.random() < 0.5
+ })
+}
function add (i, j) {
const a = i + 1
@@ -153,6 +209,7 @@ let life_bpm = 50
window.addEventListener("keydown", keydown, true)
function keydown(e){
// console.log(e.keyCode)
+ if (e.altKey || e.ctrlKey || e.metaKey) return
switch (e.keyCode){
case 32: // space
life.toggle()
@@ -166,9 +223,27 @@ function keydown(e){
life_bpm = Math.max(1, life_bpm)
life.setTempo(life_bpm)
break
+ case 71: // g
+ glider()
+ break
case 83: // s
swap_instrument()
break
+ case 67: // c
+ clear()
+ break
+ case 87: // w
+ white()
+ break
+ case 78: // n
+ noise()
+ break
+ case 69: // e
+ stripex()
+ break
+ case 82: // r
+ stripey()
+ break
}
}
keys.listen(function(index){
@@ -177,3 +252,14 @@ keys.listen(function(index){
// instrument.toggle(freq)
})
+let hash = window.location.hash || window.location.search
+if (hash.match('sin') || hash.match('organ')) {
+ instrument = organ
+}
+if (hash.match('glider')) {
+ instrument = organ
+ clear()
+ glider()
+ life.setTempo(life_bpm = 120 * 8)
+ life.toggle()
+}