Bug fixes and basic improvements

This commit is contained in:
Daniel Odendahl Jr
2017-12-09 21:39:23 +00:00
parent 23ba2f5f83
commit aa6493e60a
8 changed files with 12 additions and 13 deletions
+4 -4
View File
@@ -58,16 +58,16 @@ class CanvasUtil {
return ctx;
}
static distort(ctx, amplitude, x, y, width, height) {
static distort(ctx, amplitude, x, y, width, height, strideLevel = 4) {
const data = ctx.getImageData(x, y, width, height);
const temp = ctx.getImageData(x, y, width, height);
const stride = width * 4;
const stride = width * strideLevel;
for (let i = 0; i < width; i++) {
for (let j = 0; j < height; j++) {
const xs = Math.round(amplitude * Math.sin(2 * Math.PI * 3 * (j / height)));
const ys = Math.round(amplitude * Math.cos(2 * Math.PI * 3 * (i / width)));
const dest = (j * stride) + (i * 4);
const src = ((j + ys) * stride) + ((i + xs) * 4);
const dest = (j * stride) + (i * strideLevel);
const src = ((j + ys) * stride) + ((i + xs) * strideLevel);
data.data[dest] = temp.data[src];
data.data[dest + 1] = temp.data[src + 1];
data.data[dest + 2] = temp.data[src + 2];