@@ -5,12 +5,21 @@ class Chart {}
5
5
const canvas = document . getElementById ( "canvas" ) ;
6
6
const coord = document . getElementById ( "coord" ) ;
7
7
const plotType = document . getElementById ( "plot-type" ) ;
8
+ const pitch = document . getElementById ( "pitch" ) ;
9
+ const yaw = document . getElementById ( "yaw" ) ;
10
+ const control = document . getElementById ( "3d-control" ) ;
8
11
const status = document . getElementById ( "status" ) ;
9
12
10
13
let chart = null ;
11
14
12
15
/** Main entry point */
13
16
export function main ( ) {
17
+ let hash = location . hash . substr ( 1 ) ;
18
+ for ( var i = 0 ; i < plotType . options . length ; i ++ ) {
19
+ if ( hash == plotType . options [ i ] . value ) {
20
+ plotType . value = hash ;
21
+ }
22
+ }
14
23
setupUI ( ) ;
15
24
setupCanvas ( ) ;
16
25
}
@@ -24,6 +33,10 @@ export function setup(WasmChart) {
24
33
function setupUI ( ) {
25
34
status . innerText = "WebAssembly loaded!" ;
26
35
plotType . addEventListener ( "change" , updatePlot ) ;
36
+ yaw . addEventListener ( "change" , updatePlot ) ;
37
+ pitch . addEventListener ( "change" , updatePlot ) ;
38
+ yaw . addEventListener ( "input" , updatePlot ) ;
39
+ pitch . addEventListener ( "input" , updatePlot ) ;
27
40
window . addEventListener ( "resize" , setupCanvas ) ;
28
41
window . addEventListener ( "mousemove" , onMouseMove ) ;
29
42
}
@@ -58,15 +71,33 @@ function onMouseMove(event) {
58
71
}
59
72
}
60
73
74
+ function updatePlot3d ( ) {
75
+ let yaw_value = Number ( yaw . value ) / 100.0 ;
76
+ let pitch_value = Number ( pitch . value ) / 100.0 ;
77
+ Chart . plot3d ( canvas , pitch_value , yaw_value ) ;
78
+ coord . innerText = `Pitch:${ pitch_value } , Yaw:${ yaw_value } `
79
+ }
80
+
61
81
/** Redraw currently selected plot. */
62
82
function updatePlot ( ) {
63
83
const selected = plotType . selectedOptions [ 0 ] ;
64
84
status . innerText = `Rendering ${ selected . innerText } ...` ;
65
85
chart = null ;
66
86
const start = performance . now ( ) ;
67
- chart = ( selected . value == "mandelbrot" )
68
- ? Chart . mandelbrot ( canvas )
69
- : Chart . power ( "canvas" , Number ( selected . value ) ) ;
87
+ switch ( selected . value ) {
88
+ case "mandelbrot" :
89
+ control . classList . add ( "hide" ) ;
90
+ chart = Chart . mandelbrot ( canvas ) ;
91
+ break ;
92
+ case "3d-plot" :
93
+ control . classList . remove ( "hide" ) ;
94
+ updatePlot3d ( ) ;
95
+ break ;
96
+ default :
97
+ control . classList . add ( "hide" ) ;
98
+ chart = Chart . power ( "canvas" , Number ( selected . value ) )
99
+ }
100
+
70
101
const end = performance . now ( ) ;
71
102
status . innerText = `Rendered ${ selected . innerText } in ${ Math . ceil ( end - start ) } ms` ;
72
103
}
0 commit comments