@@ -5,12 +5,21 @@ class Chart {}
55const canvas = document . getElementById ( "canvas" ) ;
66const coord = document . getElementById ( "coord" ) ;
77const plotType = document . getElementById ( "plot-type" ) ;
8+ const pitch = document . getElementById ( "pitch" ) ;
9+ const yaw = document . getElementById ( "yaw" ) ;
10+ const control = document . getElementById ( "3d-control" ) ;
811const status = document . getElementById ( "status" ) ;
912
1013let chart = null ;
1114
1215/** Main entry point */
1316export 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+ }
1423 setupUI ( ) ;
1524 setupCanvas ( ) ;
1625}
@@ -24,6 +33,10 @@ export function setup(WasmChart) {
2433function setupUI ( ) {
2534 status . innerText = "WebAssembly loaded!" ;
2635 plotType . addEventListener ( "change" , updatePlot ) ;
36+ yaw . addEventListener ( "change" , updatePlot ) ;
37+ pitch . addEventListener ( "change" , updatePlot ) ;
38+ yaw . addEventListener ( "input" , updatePlot ) ;
39+ pitch . addEventListener ( "input" , updatePlot ) ;
2740 window . addEventListener ( "resize" , setupCanvas ) ;
2841 window . addEventListener ( "mousemove" , onMouseMove ) ;
2942}
@@ -58,15 +71,33 @@ function onMouseMove(event) {
5871 }
5972}
6073
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+
6181/** Redraw currently selected plot. */
6282function updatePlot ( ) {
6383 const selected = plotType . selectedOptions [ 0 ] ;
6484 status . innerText = `Rendering ${ selected . innerText } ...` ;
6585 chart = null ;
6686 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+
70101 const end = performance . now ( ) ;
71102 status . innerText = `Rendered ${ selected . innerText } in ${ Math . ceil ( end - start ) } ms` ;
72103}
0 commit comments