-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
175 lines (136 loc) · 5.3 KB
/
index.html
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<!DOCTYPE HTML>
<html>
<title>SSVEP Stimulator</title>
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- <script src="dist/index.js"></script> -->
<!-- <script src="https://cdn.jsdelivr.net/npm/ssvep-stimuli@latest/dist/index.esm.js"></script> -->
<link rel="stylesheet" type="text/css" href="./bootstrap.css" />
<link rel="stylesheet" type="text/css" href="./style.css" />
</head>
<body>
<div id="options">
<h4>SSVEP Options</h4>
<button id="css_periodic">CSS Periodic</button>
<button id="css_approximation">CSS Approximation</button>
<button id="webgl_periodic">WebGL Periodic</button>
<button id="webgl_approximation">WebGL Approximation</button>
<button id="cancel">Cancel</button>
</div>
<canvas id="drawing_canvas"></canvas>
<div id="content">
<div id="buttonDiv" class="container-fluid">
<div class="row my-lg-4 my-sm-0 mx-lg-1 mx-sm-0">
<div class="col-3 mr-lg-4 mr-sm-0">
<div class="SSVEP">A B C</br>D E F</br>G H I</div>
</div>
<div class="col-3 mr-lg-4 mr-sm-0">
<div class="SSVEP">J K L</br>M N O</br>P Q R</div>
</div>
<div class="col-3 mr-lg-4 mr-sm-0">
<div class="SSVEP">S T U</br>V W X</br>Y Z _</div>
</div>
</div>
<div class="row my-lg-3 my-sm-0 mx-lg-1 mx-sm-0">
<div class="col-9 my-auto">
<form name="submitForm">
<input type="text" class="sentenceArea" id="txtToType" value="HELLO" readOnly=true>
<input type="text" id="txtOutput" readOnly=true>
</form>
</div>
<!--data-phase-shift should be defined in terms of pi-->
<div class="col-3 text-right">
<div class="SSVEP">Delete</div>
</div>
</div>
<div class="row my-lg-4 my-sm-0 mx-lg-1 mx-sm-0">
<div class="col-3 mr-lg-4 mr-sm-0">
<div class="SSVEP">Word1</div>
</div>
<div class="col-3 mr-lg-4 mr-sm-0">
<div class="SSVEP">Word2</div>
</div>
<div class="col-3 mr-lg-4 mr-sm-0">
<div class="SSVEP">Word3</div>
</div>
</div>
</div>
</div>
</body>
<script type="module">
import * as stimuli from "./src/index.js"
// import * as stimuli from "./dist/index.esm.js"
// import * as stimuli from "https://cdn.jsdelivr.net/npm/ssvep-stimuli@latest/dist/index.esm.js"
// ------------------------ Arbitrary Elements ------------------------
const buttons = document.getElementById('options').querySelectorAll('button')
const elements = Array.from(document.body.querySelectorAll('.SSVEP'))
const canvas = document.body.querySelector('canvas')
// Sample Elements
const half = Math.round(elements.length / 2)
const sample1 = elements.slice(0,half)
const sample2 = elements.slice(half)
// ------------------------ Attributes ------------------------
const attributes = [
{ frequency: 6.67, },
{ frequency: 20 },
{ frequency: 8.57, },
{ frequency: 6.67, },
{ frequency: 12, },
{ frequency: 15 },
{ frequency: 6.67 },
]
const css = new stimuli.CSS('periodic', 10)
const webgl = new stimuli.WebGL('periodic', canvas, 10)
// elements.forEach(el => {
// css.set(el)
// webgl.set(el)
// })
// ------------------------ Setup Options ------------------------
let cancel = null
buttons.forEach(el => {
const [type, method] = el.id.split('_')
// Set OnClick Event
el.onclick = async () => {
// Set Method on Classes
css.method = method
if (cancel instanceof Function) cancel() // Cancel ongoing stimuli generation
if (el.id != 'cancel') {
// Step 1: Apply Frequencies to Elements
elements.forEach((element, i) => {
for (let key in attributes[i]) element.setAttribute(`data-${key}`, attributes[i][key])
})
// Step 2: Animate
const thisType = stimuli[type]
if (thisType) {
if (type === 'webgl') {
// ---------------- Simple Demo ----------------
await webgl.start(elements)
cancel = webgl.stop
// ---------------- Functional Usage ----------------
// cancel = await stimuli.webgl.start(method, elements, canvas)
} else {
// ---------------- Simple Demo ----------------
await css.start(elements)
cancel = css.stop
// ---------------- Complex Demo ----------------
// await css.start(sample1) // Activate the first half of the elements
// setTimeout(() => { // Activate the second half
// css.start(sample2)
// setTimeout(() => { // Deactivate the first half
// css.stop(sample1)
// setTimeout(() => css.start(elements), 1000) // Activate all
// }, 1000)
// }, 1000)
// cancel = css.stop
// ---------------- Functional Usage ----------------
// cancel = await stimuli.css.start(method, elements)
}
}
else console.error('This type/method pair does not exist')
}
}
})
</script>
</html>