-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
98 additions
and
35 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const WIDTH = 1280; | ||
const HEIGHT = 960; | ||
|
||
export function normalizedToPixelCoords([x, y]: [number, number]): Point { | ||
return [x * WIDTH, y * HEIGHT]; | ||
} |
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,49 @@ | ||
import tinycolor from "tinycolor2"; | ||
import { normalizedToPixelCoords } from "./geometry"; | ||
|
||
const offsetX = 10; | ||
const offsetY = 30; | ||
const width = 150; | ||
const height = 100; | ||
const separation = 20; | ||
|
||
export function setupPallete( | ||
canvasCtx: CanvasRenderingContext2D, | ||
colorIdx: number | ||
) { | ||
canvasCtx.save(); | ||
canvasCtx.clearRect(5, 15, 160, 480); | ||
colors.forEach((color, idx) => { | ||
const colorPallete = tinycolor(color); | ||
canvasCtx.fillStyle = | ||
idx === colorIdx | ||
? colorPallete.setAlpha(0.9).toString() | ||
: colorPallete.setAlpha(0.5).toString(); | ||
canvasCtx.fillRect(10, 120 * idx + 30, 150, 100); | ||
}); | ||
canvasCtx.restore(); | ||
} | ||
|
||
export function maybeSelectColor([xOrig, yOrig]: Point): number | false { | ||
const [x, y] = normalizedToPixelCoords([xOrig, yOrig]); | ||
let found: false | number = false; | ||
colors.forEach((color, idx) => { | ||
if ( | ||
x > offsetX && | ||
x < width + offsetX && | ||
y > offsetY + idx * (height + separation) && | ||
y < offsetY + idx * (height + separation) + height | ||
) { | ||
found = idx; | ||
} | ||
}); | ||
|
||
return found; | ||
} | ||
|
||
export const colors = [ | ||
"rgb(0, 161, 157, 0.5)", | ||
"rgb(255, 248, 229, 0.5)", | ||
"rgb(255, 179, 68,0.5)", | ||
"rgb(224, 93, 93,0.5)", | ||
]; |