forked from hydra-synth/hydra
-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.js
executable file
·81 lines (66 loc) · 2.02 KB
/
index.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
const PatchBay = require('./src/pb-live.js')
const HydraSynth = require('hydra-synth')
const Editor = require('./src/editor.js')
const loop = require('raf-loop')
const P5 = require('./src/p5-wrapper.js')
const Gallery = require('./src/gallery.js')
const Menu = require('./src/menu.js')
const keymaps = require('./keymaps.js')
const log = require('./src/log.js')
const repl = require('./src/repl.js')
function init () {
window.pb = pb
window.P5 = P5
var canvas = document.getElementById('hydra-canvas')
canvas.width = window.innerWidth * window.devicePixelRatio
canvas.height = window.innerHeight * window.devicePixelRatio
canvas.style.width = '100%'
canvas.style.height = '100%'
canvas.style.imageRendering = 'pixelated'
let isIOS =
(/iPad|iPhone|iPod/.test(navigator.platform) ||
(navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1)) &&
!window.MSStream;
let precisionValue = isIOS ? 'highp' : 'mediump'
var pb = new PatchBay()
var hydra = new HydraSynth({ pb: pb, canvas: canvas, autoLoop: false, precision: precisionValue})
var editor = new Editor()
var menu = new Menu({ editor: editor, hydra: hydra})
log.init()
// get initial code to fill gallery
var sketches = new Gallery(function(code, sketchFromURL) {
editor.setValue(code)
repl.eval(code)
// if a sketch was found based on the URL parameters, dont show intro window
if(sketchFromURL) {
menu.closeModal()
} else {
menu.openModal()
}
})
menu.sketches = sketches
keymaps.init ({
editor: editor,
gallery: sketches,
menu: menu,
repl: repl,
log: log
})
// define extra functions (eventually should be added to hydra-synth?)
// hush clears what you see on the screen
window.hush = () => {
solid().out()
solid().out(o1)
solid().out(o2)
solid().out(o3)
render(o0)
}
pb.init(hydra.captureStream, {
server: window.location.origin,
room: 'iclc'
})
var engine = loop(function(dt) {
hydra.tick(dt)
}).start()
}
window.onload = init