-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy path_p5Base.js
More file actions
42 lines (41 loc) · 1.04 KB
/
_p5Base.js
File metadata and controls
42 lines (41 loc) · 1.04 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
import VantaBase from './_base.js'
import {color2Hex} from './helpers.js'
export {VANTA} from './_base.js'
let p5 = (typeof window == 'object') && window.p5
export default class P5Base extends VantaBase {
constructor(userOptions) {
p5 = userOptions.p5 || p5
super(userOptions)
this.mode = 'p5'
}
initP5 (p) {
const t = this
const renderer = p.createCanvas(t.width, t.height)
renderer.parent(t.el) // put the renderer's canvas under el
t.applyCanvasStyles(p.canvas, {
background: color2Hex(t.options.backgroundColor)
})
// p.background(color2Hex(t.options.backgroundColor))
t.p5renderer = renderer
t.p5canvas = p.canvas
t.p5 = p
}
restart(){
if (this.p5 && typeof this.p5 == 'object') {
this.p5.remove()
}
super.restart()
}
destroy(){
if (this.p5 && typeof this.p5 == 'object') {
this.p5.remove()
}
super.destroy()
}
resize(){
super.resize()
if (this.p5 && this.p5.resizeCanvas) {
this.p5.resizeCanvas(this.width, this.height)
}
}
}