-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathendless_forms.js
More file actions
67 lines (54 loc) · 1.48 KB
/
endless_forms.js
File metadata and controls
67 lines (54 loc) · 1.48 KB
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
import { el, updateSize } from './util.js'
export default class EndlessForms extends HTMLElement {
connectedCallback() {
this.canvas = el('canvas', { style: 'width: 100%; height: 100%;' })
this.canvas.addEventListener('click', (e) => this.handleClick(e))
this.attachShadow({ mode: 'closed' }).append(this.canvas)
this.paused = this.paused != undefined ? this.paused : true
if (this.config == undefined)
this.defaultConfig()
if (this.data == undefined)
this.generate()
this.display()
setInterval(() => {
if (this.paused)
return
this.step()
this.display()
}, 16)
new ResizeObserver(() => {
updateSize(this.canvas)
this.display()
}).observe(this);
}
pause() {
this.paused = true
}
play() {
this.paused = false
}
reset() {
this.generate()
this.display()
}
setConfig(config) {
this.config = config
}
getData() {
return JSON.stringify({ data: this.data, config: this.config })
}
setData(text) {
const { data, config } = JSON.parse(text)
this.data = data
this.setConfig(config)
this.display()
}
handleClick() {
this.clickHandler()
this.display()
}
clickHandler() { }
display() {
this.canvas.getContext('2d').drawImage(this.getCanvas(), 0, 0)
}
}