-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Buggy zooming in / out in graphing mode & style: Improve code st…
…ructure
- Loading branch information
1 parent
488f20e
commit c3a1df2
Showing
10 changed files
with
180 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import RootToken from "@/compiler/token/RootToken"; | ||
import Evaluator from "@/compiler/Evaluator"; | ||
import { delta } from "@/workers/Render"; | ||
|
||
export default class Function { | ||
public root: RootToken; | ||
|
||
public constructor(root: RootToken) { | ||
this.root = root; | ||
} | ||
|
||
public calculate(x: number): number { | ||
return new Evaluator(this.root, new Map([["x", x.toString()]])).evaluate(); | ||
} | ||
|
||
public play(workerCtx: Worker): void { | ||
var rawPitches: number[] = []; | ||
|
||
for(let x = -8; x <= 8; x += delta) { | ||
var y = this.calculate(x); | ||
|
||
rawPitches.push(y); | ||
} | ||
|
||
const min = Math.min(...rawPitches); | ||
for(let i = 0; i < rawPitches.length && min < 0; i++) { | ||
rawPitches[i] += -min; | ||
} | ||
|
||
workerCtx.postMessage({ type: "play", rawPitches }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import Render from "@/workers/Render"; | ||
|
||
export default class Point { | ||
private renderer: Render; | ||
|
||
public x: number; | ||
public y: number; | ||
|
||
public constructor(renderer: Render, x: number, y: number) { | ||
this.renderer = renderer; | ||
this.x = x; | ||
this.y = y; | ||
} | ||
|
||
public toCoordinates(): Point { | ||
var unitPx = this.renderer.scale; | ||
return new Point(this.renderer, (this.x - this.renderer.center.x) / unitPx, -(this.y - this.renderer.center.y) / unitPx); | ||
} | ||
|
||
public toScreen(): Point { | ||
var unitPx = this.renderer.scale; | ||
return new Point(this.renderer, this.renderer.center.x + (this.x * unitPx), this.renderer.center.y - (this.y * unitPx)); | ||
} | ||
} |
Oops, something went wrong.
c3a1df2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 Published on https://calcium.js.org as production
🚀 Deployed on https://656b48247bad5352cdc6bf16--courageous-bublanina-6857c1.netlify.app