From 3a69f43f2320776c0de634b6e141d14fd0c58877 Mon Sep 17 00:00:00 2001 From: Jim Richter Date: Wed, 10 Mar 2021 14:24:50 +0100 Subject: [PATCH] fix: implement simple distortion fix --- view/public/worker.js | 4 +++- view/src/components/Editor/OrbView.ts | 2 +- view/src/components/Editor/Painter.svelte | 12 +++++------- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/view/public/worker.js b/view/public/worker.js index 9e01763..1f97a5c 100644 --- a/view/public/worker.js +++ b/view/public/worker.js @@ -28,7 +28,9 @@ self.addEventListener('message', function (e) { const y = Math.floor(i / width); // KarlKilian Formel - const pixelValue = Math.cos(360 / (Math.pow(height, 2)) * Math.pow(y, 2) + (-360 / height) * y + 90); + //const pixelValue = Math.cos(360 / (Math.pow(height, 2)) * Math.pow(y, 2) + (-360 / height) * y + 90); + + const pixelValue = (2 * Math.sqrt(y * (height - y))) / height; oldStore[id] = oldStore[id] + 1 || 1; diff --git a/view/src/components/Editor/OrbView.ts b/view/src/components/Editor/OrbView.ts index b630566..41f33ff 100644 --- a/view/src/components/Editor/OrbView.ts +++ b/view/src/components/Editor/OrbView.ts @@ -1,6 +1,6 @@ import { Renderer, Camera, Transform, Texture, Sphere, Program, Mesh } from "ogl" import { Orbit } from "./CustomOrbit" -import { bufToImageUrl } from "helpers"; +import { bufToImageUrl } from "../../helpers"; import VertexShader from "./Orb.vert"; diff --git a/view/src/components/Editor/Painter.svelte b/view/src/components/Editor/Painter.svelte index 18841b6..bfa566c 100644 --- a/view/src/components/Editor/Painter.svelte +++ b/view/src/components/Editor/Painter.svelte @@ -46,6 +46,7 @@ let downX, downOffset; let debugValue = 0; + let debugY = 0; let isStrPressed = false; let isSpacePressed = false; @@ -155,14 +156,11 @@ isOriginal = e.target.id === "cx1"; //Caclulate y position of pixel - const y = my / wrapperHeightRatio; + const y = Math.floor(my * wrapperHeightRatio); + debugY = y; // KarlKilian Formel - debugValue = Math.cos( - (360 / Math.pow(image.height, 2)) * Math.pow(y, 2) + - (-360 / image.height) * y + - 90 - ); + debugValue = (2 * Math.sqrt(y * (image.height - y))) / image.height; if (isDown) { if (activeTool === "pan") { @@ -303,7 +301,7 @@ }%)); opacity: ${(layerOpacity / 100) * 0.5};`} /> -

{debugValue}|{my}

+

h:{image.height} | y:{debugY} | value:{debugValue}