-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.ts
47 lines (39 loc) · 1.38 KB
/
main.ts
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
import * as healpix from '../../../../src'
import { PerspectiveCanvas } from "./perspective_canvas"
function draw(canvas: PerspectiveCanvas, theta: number, phi: number) {
const nstep = 8
const nside = 4
const npix = 12 * nside * nside
canvas.phi = phi
canvas.theta = theta
canvas.clear()
for (let ipix = 0; ipix < npix; ++ipix) {
canvas.path(lineTo => {
for (let i = 0; i < nstep; ++i) {
const ne = i / nstep
const v = healpix.pixcoord2vec_nest(nside, ipix, ne, 0)
lineTo(v)
}
for (let i = 0; i <= nstep; ++i) {
const nw = i / nstep
const v = healpix.pixcoord2vec_nest(nside, ipix, 1, nw)
lineTo(v)
}
})
}
}
window.addEventListener('load', e => {
const canvas = new PerspectiveCanvas(setupCanvas(document.getElementById('main') as HTMLCanvasElement))
draw(canvas, 0, 0)
window.addEventListener('mousemove', e => {
const theta = Math.PI * e.clientY / window.innerHeight
const phi = Math.PI * e.clientX / window.innerHeight
draw(canvas, theta, phi)
})
})
function setupCanvas(canvas: HTMLCanvasElement) {
const { width, height } = canvas.getBoundingClientRect()
canvas.width = width * devicePixelRatio
canvas.height = height * devicePixelRatio
return canvas
}