46
46
ctx . scale ( ratio , ratio ) ;
47
47
48
48
// 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 ) ;
53
55
54
56
// Fetch and instantiate the module
55
- fetch ( "build/optimized .wasm" )
57
+ fetch ( "build/release .wasm" )
56
58
. then ( response => response . arrayBuffer ( ) )
57
59
. 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
+ } ,
60
65
} ) )
61
66
. 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 ) {
65
70
var yx = y * width ;
66
71
for ( let x = 0 ; x < width ; ++ x ) {
67
72
argb [ yx + x ] = colors [ mem [ yx + x ] ] ;
85
90
86
91
// Let it glow a bit by occasionally shifting the limit...
87
92
var currentLimit = limit ;
88
- var shiftRange = 10 ;
93
+ const shiftRange = 10 ;
94
+
89
95
( function updateShift ( ) {
90
96
currentLimit = limit + ( 2 * Math . random ( ) * shiftRange - shiftRange ) | 0
91
97
setTimeout ( updateShift , 1000 + ( 1500 * Math . random ( ) ) | 0 ) ;
92
98
} ) ( ) ;
93
99
94
100
// ...while continously recomputing a subset of it.
95
- var flickerRange = 3 ;
101
+ const flickerRange = 3 ;
96
102
( function updateFlicker ( ) {
97
103
for ( let i = 0 , k = ( 0.05 * height ) | 0 ; i < k ; ++ i ) {
98
104
let ry = ( Math . random ( ) * height ) | 0 ;
@@ -110,15 +116,15 @@ <h1>
110
116
} ) ;
111
117
112
118
// 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 ;
116
122
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" ) ;
122
128
grd . addColorStop ( 0.6425 , "#FFAA00" ) ;
123
129
grd . addColorStop ( 0.8575 , "#000200" ) ;
124
130
ctx . fillStyle = grd ;
0 commit comments