-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
101 lines (86 loc) · 2.8 KB
/
index.js
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
import { margo_client } from "./connection.mjs"
margo_client().then(({ sendreceive }) => {
console.log("Connected!")
console.log(sendreceive)
// var i = 0
// setInterval(() => {
// i++
// const tic = Date.now()
// sendreceive("arithmetic", { a: 0, b: i }).then(() => {
// const toc = Date.now()
// console.log(toc - tic)
// })
// }, 1000)
const a_slider = document.querySelector("#a")
const b_slider = document.querySelector("#b")
const c_box = document.querySelector("#c")
const d_slider = document.querySelector("#d")
const e_slider = document.querySelector("#e")
const repaint_button = document.querySelector("#repaint")
const paint = document.querySelector("#painting")
const ctx = paint.getContext("2d")
const update_sliders = () => {
sendreceive("arithmetic", {
a: a_slider.valueAsNumber,
b: b_slider.valueAsNumber,
}).then((val) => {
c_box.value = val.sum
})
}
a_slider.addEventListener("input", update_sliders)
b_slider.addEventListener("input", update_sliders)
update_sliders()
const update_painting = () => {
sendreceive("randimage", {
width: 256,
height: 256,
}).then((val) => {
const img_data = new ImageData(new Uint8ClampedArray(val.img), 256, 256)
ctx.putImageData(img_data, 0, 0)
})
}
repaint_button.addEventListener("click", update_painting)
update_painting()
const update_opt = () => {
sendreceive("opt_controls_temp", {
opt_parameters: {
temp_goal: d_slider.valueAsNumber,
temp_final: d_slider.valueAsNumber,
max_deployment: {
mitigate: 1,
remove: 0,
geoeng: 0,
adapt: 0,
},
},
economics: {
mitigate_cost: 1,
},
}).then(console.log)
}
d_slider.addEventListener("input", update_opt)
update_opt()
const update_forward = () => {
sendreceive("forward_controls_temp", {
controls: {
M: [
0.015621145775716586,
0.06264691158067215,
0.18452063449519915,
0.39916155535584363,
0.6341776996621064,
0.74,
0.6341776996621064,
0.39916155535584363,
0.18452063449519915,
0.06264691158067215,
],
},
economics: {
mitigate_cost: 1,
},
}).then(console.log)
}
update_forward()
window.u = update_forward
})