diff --git a/package-lock.json b/package-lock.json index d19be53..d1ef352 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "2.0.0", "license": "AGPL-3.0", "dependencies": { - "@batpb/genart": "^1.1.0", + "@batpb/genart": "file://~/Desktop/npm-test/batpb-genart-2.0.0-rainbow-waves-test-007.tgz", "@types/p5": "^1.7.6", "p5": "^1.11.0" }, @@ -35,17 +35,17 @@ } }, "node_modules/@batpb/genart": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/@batpb/genart/-/genart-1.1.0.tgz", - "integrity": "sha512-QY1CwOc1+LLnbWxwfrxt5R/GaSHFFX4lbThor0NaDHOdo0YuoPzaFvI9YBJq1yoo3HJdSy42sqW5/zD6OoUoog==", + "version": "2.0.0-rainbow-waves-test-007", + "resolved": "file:../../../../../../../../../Desktop/npm-test/batpb-genart-2.0.0-rainbow-waves-test-007.tgz", + "integrity": "sha512-LYYD+jRw68A+bbzoXBoVmAEUv1jnOH92nrLa+BnLf0tC35GNQtYpSEPU9Q9DBr8ODo1sBLPCHNZrETSz6bsKFQ==", "license": "AGPL-3.0", "dependencies": { "@types/nearest-color": "^0.4.1", "@types/p5": "^1.7.6", "cococh": "^1.2.4", - "color-name-list": "^10.24.0", + "color-name-list": "^10.28.0", "nearest-color": "^0.4.4", - "p5": "^1.10.0" + "p5": "^1.11.0" } }, "node_modules/@discoveryjs/json-ext": { diff --git a/package.json b/package.json index 781772e..7ac1655 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ }, "homepage": "https://github.com/brittni-and-the-polar-bear/rainbow-waves#readme", "dependencies": { - "@batpb/genart": "^1.1.0", + "@batpb/genart": "file://~/Desktop/npm-test/batpb-genart-2.0.0-rainbow-waves-test-007.tgz", "@types/p5": "^1.7.6", "p5": "^1.11.0" }, diff --git a/src/main/sketch-screen.ts b/src/main/sketch-screen.ts new file mode 100644 index 0000000..202abf6 --- /dev/null +++ b/src/main/sketch-screen.ts @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2024 brittni and the polar bear LLC. + * + * This file is a part of brittni and the polar bear's rainbow waves algorithmic art project, + * which is released under the GNU Affero General Public License, Version 3.0. + * You may not use this file except in compliance with the license. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. See LICENSE or go to + * https://www.gnu.org/licenses/agpl-3.0.en.html for full license details. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Affero General Public License for more details. + * + * The visual outputs of this source code are licensed under the + * Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0) License. + * You should have received a copy of the CC BY-NC-ND 4.0 License with this program. + * See OUTPUT-LICENSE or go to https://creativecommons.org/licenses/by-nc-nd/4.0/ + * for full license details. + */ + +import { CanvasScreen, P5Context } from '@batpb/genart'; + +export class SketchScreen extends CanvasScreen { + public constructor() { + super('sketch'); + } + + public draw(): void { + P5Context.p5.background(0, 175, 0); + } + + public keyPressed(): void { + console.log('keyPressed'); + } + + public mousePressed(): void { + console.log('mousePressed'); + } +} diff --git a/src/main/sketch.ts b/src/main/sketch.ts index 9b4e230..2344237 100644 --- a/src/main/sketch.ts +++ b/src/main/sketch.ts @@ -1,3 +1,5 @@ +// noinspection DuplicatedCode + /* * Copyright (C) 2015-2024 brittni and the polar bear LLC. * @@ -23,20 +25,40 @@ import P5Lib from 'p5'; -import { Color } from '@batpb/genart'; +import { + ASPECT_RATIOS, + CanvasContext, + P5Context, + ScreenHandler +} from '@batpb/genart'; import '../../assets/styles/sketch.css'; +import { SketchScreen } from './sketch-screen'; + function sketch(p5: P5Lib): void { p5.setup = (): void => { - p5.createCanvas(500, 500); + P5Context.initialize(p5); + CanvasContext.buildCanvas(ASPECT_RATIOS.SQUARE, 720, p5.P2D, true); + const screen: SketchScreen = new SketchScreen(); + ScreenHandler.addScreen(screen); + ScreenHandler.currentScreen = screen.NAME; }; p5.draw = (): void => { - const bg: Color = new Color(255, 50, 180); - p5.background(bg.color); - p5.rectMode(p5.CENTER); - p5.rect(p5.width / 2.0, p5.height / 2.0, 100, 100); + ScreenHandler.draw(); + }; + + p5.keyPressed = (): void => { + ScreenHandler.keyPressed(); + }; + + p5.mousePressed = (): void => { + ScreenHandler.mousePressed(); + }; + + p5.windowResized = (): void => { + CanvasContext.resizeCanvas(); }; } diff --git a/src/main/wave/point.ts b/src/main/wave/point.ts new file mode 100644 index 0000000..2199286 --- /dev/null +++ b/src/main/wave/point.ts @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2024 brittni and the polar bear LLC. + * + * This file is a part of brittni and the polar bear's rainbow waves algorithmic art project, + * which is released under the GNU Affero General Public License, Version 3.0. + * You may not use this file except in compliance with the license. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. See LICENSE or go to + * https://www.gnu.org/licenses/agpl-3.0.en.html for full license details. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Affero General Public License for more details. + * + * The visual outputs of this source code are licensed under the + * Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0) License. + * You should have received a copy of the CC BY-NC-ND 4.0 License with this program. + * See OUTPUT-LICENSE or go to https://creativecommons.org/licenses/by-nc-nd/4.0/ + * for full license details. + */ + +import {CanvasRedrawListener, Color, Coordinate, Point as PointShape} from '@batpb/genart' +import P5Lib from "p5"; + +export class Point implements CanvasRedrawListener { + #base: Coordinate = new Coordinate(); + #point: PointShape; + #theta: number; + #amplitude: number; + #deltaTheta: number; + + public constructor(base: P5Lib.Vector, theta: number, amp: number, deltaTheta: number) { + this.#base.position = base; + this.#theta = theta; + this.#amplitude = amp; + this.#deltaTheta = deltaTheta; + this.#point = new PointShape(); + this.#updatePosition(); + this.#point.stroke = new Color(255, 0, 0); + } + + public draw(): void { + this.#point.draw(); + this.update(); + } + + public update(): void { + this.#theta += this.#deltaTheta; + } + + public canvasRedraw(): void { + this.#point.canvasRedraw(); + } + + #updatePosition(): void { + this.#point.x = this.#base.x; + this.#point.y = this.#calculateY(); + } + + #calculateY(): number { + return this.#base.y + (Math.sin(this.#theta) * this.#amplitude); + } +} diff --git a/src/main/wave/wave.ts b/src/main/wave/wave.ts new file mode 100644 index 0000000..7a28a00 --- /dev/null +++ b/src/main/wave/wave.ts @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2015-2024 brittni and the polar bear LLC. + * + * This file is a part of brittni and the polar bear's rainbow waves algorithmic art project, + * which is released under the GNU Affero General Public License, Version 3.0. + * You may not use this file except in compliance with the license. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. See LICENSE or go to + * https://www.gnu.org/licenses/agpl-3.0.en.html for full license details. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Affero General Public License for more details. + * + * The visual outputs of this source code are licensed under the + * Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0) License. + * You should have received a copy of the CC BY-NC-ND 4.0 License with this program. + * See OUTPUT-LICENSE or go to https://creativecommons.org/licenses/by-nc-nd/4.0/ + * for full license details. + */ + +import P5Lib, {length} from "p5"; +import {Point} from "./point"; +import {CanvasRedrawListener, P5Context} from "@batpb/genart"; + +export class Wave implements CanvasRedrawListener { + #base: P5Lib.Vector; + #length: number; + #amplitude: number; + #frequency: number; + #pointCount: number; + #deltaTheta: number; + readonly #points: Point[] = []; + + constructor(base: P5Lib.Vector, length: number, amplitude: number, frequency: number, pointCount: number) { + this.#base = base; + this.#length = length; + this.#amplitude = amplitude; + this.#frequency = frequency; + this.#pointCount = pointCount; + this.#deltaTheta = 0.01; + this.#buildPoints(); + } + + #buildPoints(): void { + let theta: number = 0; + + for (let i: number = 0; i < this.#pointCount; i++) { + const pointBase: P5Lib.Vector = new P5Lib.Vector(); + pointBase.x = this.#base.x + (i * (this.#length / this.#pointCount)); + pointBase.y = this.#base.y; + const point: Point = new Point(pointBase, theta, this.#amplitude, this.#deltaTheta); + this.#points.push(point); + theta += ((P5Context.p5.TWO_PI * this.#frequency) / this.#pointCount); + } + } + + canvasRedraw(): void { + this.#points.forEach((point: Point): void => point.canvasRedraw()); + } + + draw(): void { + } +} diff --git a/src/to-do.js b/src/to-do.js new file mode 100644 index 0000000..072a4dd --- /dev/null +++ b/src/to-do.js @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2024 brittni and the polar bear LLC. + * + * This file is a part of brittni and the polar bear's rainbow waves algorithmic art project, + * which is released under the GNU Affero General Public License, Version 3.0. + * You may not use this file except in compliance with the license. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. See LICENSE or go to + * https://www.gnu.org/licenses/agpl-3.0.en.html for full license details. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Affero General Public License for more details. + * + * The visual outputs of this source code are licensed under the + * Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0) License. + * You should have received a copy of the CC BY-NC-ND 4.0 License with this program. + * See OUTPUT-LICENSE or go to https://creativecommons.org/licenses/by-nc-nd/4.0/ + * for full license details. + */ + +// TODO - layouts +// TODO - horizontal +// TODO - vertical +// TODO - gabriel graph +// TODO - random geometric graph (maybe?) + +// TODO - graph point distributions +// TODO - square +// TODO - circle +// TODO - poisson distribution (code train tutorial) +// TODO - square lattice +// TODO - equilateral triangle lattice +// TODO - hexagon lattice +// TODO - rhombic lattice +// TODO - rectangular lattice +// TODO - oblique lattice