-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
85 lines (68 loc) · 2.18 KB
/
index.js
File metadata and controls
85 lines (68 loc) · 2.18 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import * as fns from './programs/programs.js'
import { migrateToObj, sortKVPair } from './utils.js'
import data from './metadata.json'
const canvas = document.createElement('canvas')
const ctx = canvas.getContext('2d')
ctx.imageSmoothingEnabled = false
document.getElementById('canvas').appendChild(canvas)
function resize() {
const parent = document.querySelector('section#canvas')
console.log(parent.offsetWidth, parent.offsetHeight)
const size = Math.min(parent.offsetWidth, parent.offsetHeight) * .9
canvas.style.width = size
canvas.style.height = size
canvas.width = Math.ceil(size / 1000) * 1000
canvas.height = Math.ceil(size / 1000) * 1000
const scale = window.devicePixelRatio
canvas.width = canvas.width * scale
canvas.height = canvas.height * scale
ctx.scale(scale, scale)
ctx.imageSmoothingEnabled = false
ctx.webkitImageSmoothingEnabled = false
ctx.msImageSmoothingEnabled = false
window.requestAnimationFrame(() =>
draw(ctx, canvas.width, canvas.height)
)
}
window.addEventListener('resize', resize, true)
resize()
function setup(fns, ctx, w, h) {
this.fns = fns
this.ctx = ctx
this.w = w
this.h = h
this.render
const render = (self) => {
let fn
if (!('prog' in this.fns[self.name])) {
fn = migrateToObj(this.fns[self.name])
} else {
fn = this.fns[self.name]
}
fn.prog(this.ctx, this.w, this.h)
}
this.randomise = () => {
let name = Object.keys(this.fns)[
Math.floor(Math.random() * Object.keys(this.fns).length)
]
this.render = () => { render({name: name}) }
}
this.latest = () => {
// TODO: add meta filtering here based on dates
let name = Object.keys(sortKVPair(data, true))[0].split('.')[0]
this.render = () => { render({name: name}) }
}
this.override = (name) => {
this.render = () => { render({name: name}) }
}
}
function draw(ctx, w, h) {
ctx.save()
const listOfFns = fns
const fn = new setup(listOfFns, ctx, w, h)
// fn.randomise()
fn.latest()
// fn.override('text_framing')
fn.render()
ctx.restore()
}