Skip to content

Commit dc11e44

Browse files
authored
[docs] Fix a minor bug in binding tutorial (#6698)
To calculate y coordinate of `imageData`, we should divide the index with `canvas.width` not with `canvas.height`. The current code works because the shape of canvas is square.
1 parent 4d30ef3 commit dc11e44

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

site/content/tutorial/06-bindings/12-bind-this/app-a/App.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
for (let p = 0; p < imageData.data.length; p += 4) {
1616
const i = p / 4;
1717
const x = i % canvas.width;
18-
const y = i / canvas.height >>> 0;
18+
const y = i / canvas.width >>> 0;
1919
2020
const r = 64 + (128 * x / canvas.width) + (64 * Math.sin(t / 1000));
2121
const g = 64 + (128 * y / canvas.height) + (64 * Math.cos(t / 1000));
@@ -49,4 +49,4 @@
4949
-webkit-mask: url(svelte-logo-mask.svg) 50% 50% no-repeat;
5050
mask: url(svelte-logo-mask.svg) 50% 50% no-repeat;
5151
}
52-
</style>
52+
</style>

site/content/tutorial/06-bindings/12-bind-this/app-b/App.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
for (let p = 0; p < imageData.data.length; p += 4) {
1616
const i = p / 4;
1717
const x = i % canvas.width;
18-
const y = i / canvas.height >>> 0;
18+
const y = i / canvas.width >>> 0;
1919
2020
const r = 64 + (128 * x / canvas.width) + (64 * Math.sin(t / 1000));
2121
const g = 64 + (128 * y / canvas.height) + (64 * Math.cos(t / 1000));
@@ -50,4 +50,4 @@
5050
-webkit-mask: url(svelte-logo-mask.svg) 50% 50% no-repeat;
5151
mask: url(svelte-logo-mask.svg) 50% 50% no-repeat;
5252
}
53-
</style>
53+
</style>

0 commit comments

Comments
 (0)