4646ctx . scale ( ratio , ratio ) ;
4747
4848// Compute the size of and instantiate the module's memory
49- var memory = new WebAssembly . Memory ( { initial : ( ( byteSize + 0xffff ) & ~ 0xffff ) >>> 16 } ) ;
50- var mem = new Uint16Array ( memory . buffer ) ;
51- var imageData = ctx . createImageData ( width , height ) ;
52- var argb = new Uint32Array ( imageData . data . buffer ) ;
49+ const memory = new WebAssembly . Memory ( {
50+ initial : ( ( byteSize + 0xffff ) & ~ 0xffff ) >>> 16
51+ } ) ;
52+ const mem = new Uint16Array ( memory . buffer ) ;
53+ const imageData = ctx . createImageData ( width , height ) ;
54+ const argb = new Uint32Array ( imageData . data . buffer ) ;
5355
5456// Fetch and instantiate the module
55- fetch ( "build/optimized .wasm" )
57+ fetch ( "build/release .wasm" )
5658. then ( response => response . arrayBuffer ( ) )
5759. then ( buffer => WebAssembly . instantiate ( buffer , {
58- env : { memory } ,
59- Math
60+ env : {
61+ memory,
62+ "Math.log" : Math . log ,
63+ "Math.log2" : Math . log2
64+ } ,
6065} ) )
6166. then ( module => {
62- var exports = module . instance . exports ;
63- var computeLine = exports . computeLine ;
64- var updateLine = function ( y ) {
67+ const exports = module . instance . exports ;
68+ const computeLine = exports . computeLine ;
69+ const updateLine = function ( y ) {
6570 var yx = y * width ;
6671 for ( let x = 0 ; x < width ; ++ x ) {
6772 argb [ yx + x ] = colors [ mem [ yx + x ] ] ;
8590
8691 // Let it glow a bit by occasionally shifting the limit...
8792 var currentLimit = limit ;
88- var shiftRange = 10 ;
93+ const shiftRange = 10 ;
94+
8995 ( function updateShift ( ) {
9096 currentLimit = limit + ( 2 * Math . random ( ) * shiftRange - shiftRange ) | 0
9197 setTimeout ( updateShift , 1000 + ( 1500 * Math . random ( ) ) | 0 ) ;
9298 } ) ( ) ;
9399
94100 // ...while continously recomputing a subset of it.
95- var flickerRange = 3 ;
101+ const flickerRange = 3 ;
96102 ( function updateFlicker ( ) {
97103 for ( let i = 0 , k = ( 0.05 * height ) | 0 ; i < k ; ++ i ) {
98104 let ry = ( Math . random ( ) * height ) | 0 ;
@@ -110,15 +116,15 @@ <h1>
110116} ) ;
111117
112118// Compute a nice set of colors using a gradient
113- var colors = ( ( ) => {
114- var cnv = document . createElement ( "canvas" ) ;
115- cnv . width = 2048 ;
119+ const colors = ( ( ) => {
120+ const cnv = document . createElement ( "canvas" ) ;
121+ cnv . width = 2048 ;
116122 cnv . height = 1 ;
117- var ctx = cnv . getContext ( "2d" ) ;
118- var grd = ctx . createLinearGradient ( 0 , 0 , 2048 , 0 ) ;
119- grd . addColorStop ( 0.00 , "#000764" ) ;
120- grd . addColorStop ( 0.16 , "#2068CB" ) ;
121- grd . addColorStop ( 0.42 , "#EDFFFF" ) ;
123+ const ctx = cnv . getContext ( "2d" ) ;
124+ const grd = ctx . createLinearGradient ( 0 , 0 , 2048 , 0 ) ;
125+ grd . addColorStop ( 0.0000 , "#000764" ) ;
126+ grd . addColorStop ( 0.1600 , "#2068CB" ) ;
127+ grd . addColorStop ( 0.4200 , "#EDFFFF" ) ;
122128 grd . addColorStop ( 0.6425 , "#FFAA00" ) ;
123129 grd . addColorStop ( 0.8575 , "#000200" ) ;
124130 ctx . fillStyle = grd ;
0 commit comments