File tree 2 files changed +6
-10
lines changed
site/content/tutorial/06-bindings/12-bind-this
2 files changed +6
-10
lines changed Original file line number Diff line number Diff line change 5
5
6
6
onMount (() => {
7
7
const ctx = canvas .getContext (' 2d' );
8
- let frame;
8
+ let frame = requestAnimationFrame (loop) ;
9
9
10
- ( function loop () {
10
+ function loop (t ) {
11
11
frame = requestAnimationFrame (loop);
12
12
13
13
const imageData = ctx .getImageData (0 , 0 , canvas .width , canvas .height );
17
17
const x = i % canvas .width ;
18
18
const y = i / canvas .height >>> 0 ;
19
19
20
- const t = window .performance .now ();
21
-
22
20
const r = 64 + (128 * x / canvas .width ) + (64 * Math .sin (t / 1000 ));
23
21
const g = 64 + (128 * y / canvas .height ) + (64 * Math .cos (t / 1000 ));
24
22
const b = 128 ;
30
28
}
31
29
32
30
ctx .putImageData (imageData, 0 , 0 );
33
- }());
31
+ }
34
32
35
33
return () => {
36
34
cancelAnimationFrame (frame);
Original file line number Diff line number Diff line change 5
5
6
6
onMount (() => {
7
7
const ctx = canvas .getContext (' 2d' );
8
- let frame;
8
+ let frame = requestAnimationFrame (loop) ;
9
9
10
- ( function loop () {
10
+ function loop (t ) {
11
11
frame = requestAnimationFrame (loop);
12
12
13
13
const imageData = ctx .getImageData (0 , 0 , canvas .width , canvas .height );
17
17
const x = i % canvas .width ;
18
18
const y = i / canvas .height >>> 0 ;
19
19
20
- const t = window .performance .now ();
21
-
22
20
const r = 64 + (128 * x / canvas .width ) + (64 * Math .sin (t / 1000 ));
23
21
const g = 64 + (128 * y / canvas .height ) + (64 * Math .cos (t / 1000 ));
24
22
const b = 128 ;
30
28
}
31
29
32
30
ctx .putImageData (imageData, 0 , 0 );
33
- }());
31
+ }
34
32
35
33
return () => {
36
34
cancelAnimationFrame (frame);
You can’t perform that action at this time.
0 commit comments