Skip to content

Commit

Permalink
refactor: migrate @vighnesh153/graphics-programming to deno
Browse files Browse the repository at this point in the history
  • Loading branch information
vighnesh153 committed Oct 27, 2024
1 parent bd50910 commit bcd651c
Show file tree
Hide file tree
Showing 125 changed files with 247 additions and 284 deletions.
10 changes: 10 additions & 0 deletions deno-tools/tools-browser/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"cSpell.words": [
"barnsleys",
"csstype",
"euclidian",
"gameplay",
"neighbour",
"sierpinskis"
]
}
9 changes: 8 additions & 1 deletion deno-tools/tools-browser/deno.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
{
"name": "@vighnesh153/tools-browser",
"version": "0.1.0",
"exports": "./src/mod.ts",
"exports": {
".": "./src/mod.ts",
"./graphics_programming": "./src/graphics_programming/mod.ts"
},
"license": "MIT",
"imports": {
"@std/assert": "jsr:@std/assert@1",
"@std/random": "jsr:@std/random@^0.1.0",
"@vighnesh153/tools": "jsr:@vighnesh153/tools@^0.1.2",
"csstype": "npm:csstype@^3.1.3",
"js-cookie": "npm:js-cookie@^3.0.5"
},
"compilerOptions": {
"lib": ["dom", "esnext"],
"types": ["./src/globals.d.ts"]
},
"publish": {
Expand Down
32 changes: 32 additions & 0 deletions deno-tools/tools-browser/deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CanvasWrapper } from "@/canvas-wrapper.ts";
import { getCanvasBgColor } from "@/getCanvasBgColor.ts";
import { BarnsleysFernGenerator } from "./BarnsleysFernGenerator.ts";
import type { CanvasWrapper } from "../canvas_wrapper.ts";
import { getCanvasBgColor } from "../get_canvas_bg_color.ts";
import { BarnsleysFernGenerator } from "./barnsleys_fern_generator.ts";

interface GameOptions {
bgColor?: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { BarnsleysFern } from "./game.ts";
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CanvasWrapper } from "@/canvas-wrapper.ts";
import { Particle } from "./Particle.ts";
import { calculateStrength, Strength } from "./strength.ts";
import type { CanvasWrapper } from "../canvas_wrapper.ts";
import type { Particle } from "./particle.ts";
import { calculateStrength, type Strength } from "./strength.ts";

const StrengthToBondColorOpacity: Record<Strength, number> = {
NIL: 0,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { CanvasWrapper } from "@/canvas-wrapper.ts";
import { Particle } from "./Particle.ts";
import { createPosition, Position } from "./Position.ts";
import type { CanvasWrapper } from "../canvas_wrapper.ts";
import { Particle } from "./particle.ts";
import { createPosition, type Position } from "./position.ts";
import { Bond } from "./Bond.ts";
import { euclidianDistance } from "./euclidian-distance.ts";
import { euclidianDistance } from "./euclidian_distance.ts";

interface GameOptions {
mouseDeflectionDistance?: number;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { BondingParticlesGame } from "./game.ts";
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CanvasWrapper } from "@/canvas-wrapper.ts";
import { Position } from "./Position.ts";
import { createVelocity, Velocity } from "./velocity.ts";
import type { CanvasWrapper } from "../canvas_wrapper.ts";
import type { Position } from "./position.ts";
import { createVelocity, type Velocity } from "./velocity.ts";

interface ParticleConfig {
radius: number;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Position } from "./Position.ts";
import { euclidianDistance } from "./euclidian-distance.ts";
import type { Position } from "./position.ts";
import { euclidianDistance } from "./euclidian_distance.ts";

export type Strength = "NIL" | "XS" | "S" | "M" | "L" | "XL";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CanvasWrapper } from "@/canvas-wrapper.ts";
import type { CanvasWrapper } from "../canvas_wrapper.ts";

interface BallOptions {
readonly size?: number;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { not } from "@vighnesh153/tools";
import { CanvasWrapper } from "@/canvas-wrapper.ts";
import type { CanvasWrapper } from "../canvas_wrapper.ts";

interface BrickOptions {
readonly row: number;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { repeat } from "@vighnesh153/tools";
import { Brick } from "./Brick.ts";
import type { Brick } from "./brick.ts";

type BrickCreator = (row: number, column: number) => Brick;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { not } from "@vighnesh153/tools";
import { CanvasWrapper } from "@/canvas-wrapper.ts";
import { getCanvasBgColor } from "@/getCanvasBgColor.ts";
import { Paddle } from "./Paddle.ts";
import { Ball } from "./Ball.ts";
import { ScoreTracker } from "./ScoreTracker.ts";
import { Brick } from "./Brick.ts";
import { createBricksGrid } from "./createBricksGrid.ts";
import type { CanvasWrapper } from "../canvas_wrapper.ts";
import { getCanvasBgColor } from "../get_canvas_bg_color.ts";
import { Paddle } from "./paddle.ts";
import { Ball } from "./ball.ts";
import { ScoreTracker } from "./score_tracker.ts";
import { Brick } from "./brick.ts";
import { createBricksGrid } from "./create_bricks_grid.ts";

interface BrickBreakerGameOptions {
readonly bgColor?: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { BrickBreakerGame } from "./game.ts";
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CanvasWrapper } from "@/canvas-wrapper.ts";
import type { CanvasWrapper } from "../canvas_wrapper.ts";

interface PaddleOptions {
readonly width?: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,4 @@ export const gamesProjectsMap = {
export const gamesProjects: CanvasProject[] = Object.values(gamesProjectsMap);

export const canvasProjectSourceCodeLink =
"https://github.com/vighnesh153/vighnesh153-monorepo/tree/main/nodejs-tools/nodejs-lib/graphics-programming/src";
"https://github.com/vighnesh153/vighnesh153-monorepo/tree/main/deno-tools/tools-browser/src/graphics-programming";
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export function dpr(): number {
try {
return window.devicePixelRatio ?? 1;
return globalThis.devicePixelRatio ?? 1;
} catch {
return 1;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CanvasWrapper } from "@/canvas-wrapper.ts";
import type { CanvasWrapper } from "../canvas_wrapper.ts";

interface BlockConfig {
readonly coordinate: Coordinate;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { CanvasWrapper } from "@/canvas-wrapper.ts";
import { getCanvasBgColor } from "@/getCanvasBgColor.ts";
import { ScoreTracker } from "./ScoreTracker.ts";
import { InfoScreen } from "./InfoScreen.ts";
import { Screen } from "./Screen.ts";
import { GameplayScreen } from "./GameplayScreen.ts";
import type { CanvasWrapper } from "../canvas_wrapper.ts";
import { getCanvasBgColor } from "../get_canvas_bg_color.ts";
import { ScoreTracker } from "./score_tracker.ts";
import { InfoScreen } from "./info_screen.ts";
import type { Screen } from "./screen.ts";
import { GameplayScreen } from "./gameplay_screen.ts";

interface FlappyBlockGameOptions {
readonly bgColor?: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Queue } from "@vighnesh153/tools";
import { CanvasWrapper } from "@/canvas-wrapper.ts";
import { Screen } from "./Screen.ts";
import { ScoreTracker } from "./ScoreTracker.ts";
import { TwoWayPipe } from "./TwoWayPipe.ts";
import { Block } from "./Block.ts";
import type { CanvasWrapper } from "../canvas_wrapper.ts";
import type { Screen } from "./screen.ts";
import type { ScoreTracker } from "./score_tracker.ts";
import { TwoWayPipe } from "./two_way_pipe.ts";
import { Block } from "./block.ts";

interface GameplayScreenOptions {
readonly verticalPadding: number;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CanvasWrapper } from "@/canvas-wrapper.ts";
import { ScoreTracker } from "./ScoreTracker.ts";
import { Screen } from "./Screen.ts";
import type { CanvasWrapper } from "../canvas_wrapper.ts";
import type { ScoreTracker } from "./score_tracker.ts";
import type { Screen } from "./screen.ts";

interface InfoScreenOptions {
scoreTracker: ScoreTracker;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { FlappyBlockGame } from "./game.ts";
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { randomIntegerBetween } from "@std/random";
import { CanvasWrapper } from "@/canvas-wrapper.ts";
import type { CanvasWrapper } from "../canvas_wrapper.ts";

interface TwoWayPipeOptions {
verticalPadding: number;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CanvasWrapper } from "./canvas-wrapper.ts";
import type { CanvasWrapper } from "./canvas_wrapper.ts";

export function getCanvasBgColor(
canvasWrapper: CanvasWrapper,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CellPosition } from "./CellPosition.ts";
import { CellPosition } from "./cell_position.ts";

export type CellType = "empty" | "start" | "end" | "wall";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type Properties } from "csstype";
import { GridPathFinderGame } from "./Game.ts";
import type { Properties } from "csstype";
import type { GridPathFinderGame } from "./game.ts";

const gridPathFinderCellColors = {
emptyCell: "white",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BfsCell } from "./Cell.ts";
import { CellPosition } from "./CellPosition.ts";
import { BfsCell } from "./cell.ts";
import { CellPosition } from "./cell_position.ts";

function createCellsBoard(rows: number, cols: number): BfsCell[][] {
return Array.from({ length: rows }, () => Array.from({ length: cols }));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { not } from "@vighnesh153/tools";

import { CellPosition } from "./CellPosition.ts";
import { CellsGrid } from "./CellsGrid.ts";
import { BfsCell } from "./Cell.ts";
import type { CellPosition } from "./cell_position.ts";
import type { CellsGrid } from "./cells_grid.ts";
import type { BfsCell } from "./cell.ts";

function getRandomEmptyCell(grid: CellsGrid): BfsCell | null {
const emptyCells = grid.mapEachCell((cell) => cell).filter((cell) =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { not, Queue } from "@vighnesh153/tools";

import { BfsCell } from "./Cell.ts";
import { CellsGrid } from "./CellsGrid.ts";
import type { BfsCell } from "./cell.ts";
import { CellsGrid } from "./cells_grid.ts";
import { fillGridWithStartAndEnd, fillGridWithWalls } from "./factories.ts";
import { CellPosition } from "./CellPosition.ts";
import { CellPosition } from "./cell_position.ts";

export class GridPathFinderGame {
#grid: CellsGrid;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { not } from "@vighnesh153/tools";
import { GridPathFinderGame } from "./Game.ts";
import type { GridPathFinderGame } from "./game.ts";

export class GridPathFinderGameManager {
#game: GridPathFinderGame;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from "./cell_colors.ts";
export * from "./game.ts";
export * from "./game_manager.ts";
18 changes: 18 additions & 0 deletions deno-tools/tools-browser/src/graphics_programming/mod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export * from "./barnsleys_fern/mod.ts";
export * from "./bonding_particles/mod.ts";
export * from "./brick_breaker_game/mod.ts";
export * from "./flappy_block_game/mod.ts";
export * from "./grid_path_finder/mod.ts";
export * from "./pong_game/mod.ts";
export * from "./pseudo_hilbert_curve/mod.ts";
export * from "./sierpinskis_triangle/mod.ts";
export * from "./snake_game/mod.ts";
export * from "./sorting_visualizer/mod.ts";
export * from "./symmetric_binary_tree/mod.ts";
export * from "./tower_of_hanoi/mod.ts";
export * from "./tree_path_finder/mod.ts";
export * from "./twinkling_stars/mod.ts";

export * from "./canvas_wrapper.ts";
export * from "./collection.ts";
export * from "./dpr.ts";
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { CanvasWrapper } from "@/canvas-wrapper.ts";
import { ScoreTracker } from "./score-tracker.ts";
import type { CanvasWrapper } from "../canvas_wrapper.ts";
import type { ScoreTracker } from "./score_tracker.ts";
import { Pad } from "./Pad.ts";
import { Ball } from "./Ball.ts";
import { ComputerPadController } from "./ComputerPadController.ts";
import { Ball } from "./ball.ts";
import { ComputerPadController } from "./computer_pad_controller.ts";

interface ArenaOptions {
contentColor?: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CanvasWrapper } from "@/canvas-wrapper.ts";
import { Point } from "./Point.ts";
import type { CanvasWrapper } from "../canvas_wrapper.ts";
import type { Point } from "./point.ts";

interface Velocity {
dx: number;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Ball } from "./Ball.ts";
import { Pad } from "./Pad.ts";
import type { Ball } from "./ball.ts";
import type { Pad } from "./Pad.ts";

interface ComputerPadControllerConfig {
computerPad: Pad;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Point } from "./Point.ts";
import type { Point } from "./point.ts";

export function euclideanDistance(p1: Point, p2: Point): number {
const dx = p1.x - p2.x;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CanvasWrapper } from "@/canvas-wrapper.ts";
import { getCanvasBgColor } from "@/getCanvasBgColor.ts";
import { ScoreTracker } from "./score-tracker.ts";
import { Arena } from "./Arena.ts";
import type { CanvasWrapper } from "../canvas_wrapper.ts";
import { getCanvasBgColor } from "../get_canvas_bg_color.ts";
import { ScoreTracker } from "./score_tracker.ts";
import { Arena } from "./arena.ts";

interface GameOptions {
bgColor?: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { PongGame } from "./game.ts";
Loading

0 comments on commit bcd651c

Please sign in to comment.