From dfb409af4b60158dec4a94f9c6c4488b8c5ad525 Mon Sep 17 00:00:00 2001 From: azurepolarbear Date: Sun, 27 Oct 2024 21:11:21 -0500 Subject: [PATCH 1/4] Update genart library version for local testing --- package-lock.json | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index d19be53..53bc7af 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-001.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-001", + "resolved": "file:../../../../../../../../../Desktop/npm-test/batpb-genart-2.0.0-rainbow-waves-test-001.tgz", + "integrity": "sha512-GaivNlt3FFGMKwIYgknuDQHZ05NC6E9xZm10sCnbQ176qB3IV93XMAz+NBhXHz+snbQ06/qqLb1HCZn9FnHfwA==", "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 65b44ad..a063f35 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-001.tgz", "@types/p5": "^1.7.6", "p5": "^1.11.0" }, From 2c7a1bf8924ce1e7572e5e3cb88e3ae9d27356bf Mon Sep 17 00:00:00 2001 From: azurepolarbear Date: Sun, 27 Oct 2024 23:53:11 -0500 Subject: [PATCH 2/4] Working on logic to build and move wave points in Canvas space. --- package-lock.json | 8 +++---- package.json | 2 +- src/main/sketch-screen.ts | 42 +++++++++++++++++++++++++++++++++ src/main/sketch.ts | 34 ++++++++++++++++++++++----- src/main/wave/point.ts | 48 ++++++++++++++++++++++++++++++++++++++ src/main/wave/wave.ts | 49 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 172 insertions(+), 11 deletions(-) create mode 100644 src/main/sketch-screen.ts create mode 100644 src/main/wave/point.ts create mode 100644 src/main/wave/wave.ts diff --git a/package-lock.json b/package-lock.json index 53bc7af..59c17fa 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "2.0.0", "license": "AGPL-3.0", "dependencies": { - "@batpb/genart": "file://~/Desktop/npm-test/batpb-genart-2.0.0-rainbow-waves-test-001.tgz", + "@batpb/genart": "file://~/Desktop/npm-test/batpb-genart-2.0.0-rainbow-waves-test-004.tgz", "@types/p5": "^1.7.6", "p5": "^1.11.0" }, @@ -35,9 +35,9 @@ } }, "node_modules/@batpb/genart": { - "version": "2.0.0-rainbow-waves-test-001", - "resolved": "file:../../../../../../../../../Desktop/npm-test/batpb-genart-2.0.0-rainbow-waves-test-001.tgz", - "integrity": "sha512-GaivNlt3FFGMKwIYgknuDQHZ05NC6E9xZm10sCnbQ176qB3IV93XMAz+NBhXHz+snbQ06/qqLb1HCZn9FnHfwA==", + "version": "2.0.0-rainbow-waves-test-004", + "resolved": "file:../../../../../../../../../Desktop/npm-test/batpb-genart-2.0.0-rainbow-waves-test-004.tgz", + "integrity": "sha512-wr7aUoWF6RlUfhgTULMq7v7J6+ExMwqgyJfGC76AZuT9ouFjNMLpErbua6jPVXemXYbjwBfTXUBIq84mz6Mtsw==", "license": "AGPL-3.0", "dependencies": { "@types/nearest-color": "^0.4.1", diff --git a/package.json b/package.json index a063f35..ec8a281 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": "file://~/Desktop/npm-test/batpb-genart-2.0.0-rainbow-waves-test-001.tgz", + "@batpb/genart": "file://~/Desktop/npm-test/batpb-genart-2.0.0-rainbow-waves-test-004.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..5d4b40a --- /dev/null +++ b/src/main/wave/point.ts @@ -0,0 +1,48 @@ +/* + * 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 {Coordinate, Point as PointShape} from '@batpb/genart' +import P5Lib from "p5"; + +export class Point { + #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; + } + + #updatePosition(): void { + + } + + #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..694cd84 --- /dev/null +++ b/src/main/wave/wave.ts @@ -0,0 +1,49 @@ +/* + * 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 from "p5"; +import {Point} from "./point"; + +export class Wave { + #base: P5Lib.Vector; + #length: number; + #amplitude: number; + #frequency: number; + #pointCount: number; + #deltaTheta: number; + const #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 { + + } +} From 317d07fb8586ec5c4d4a6da7fcf462aa857fce5b Mon Sep 17 00:00:00 2001 From: azurepolarbear Date: Mon, 28 Oct 2024 11:29:49 -0500 Subject: [PATCH 3/4] Make file to hold general TODO items --- src/to-do.js | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/to-do.js 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 From 06b5465e05d1bf4589f3b2c9e02c0d7613d6d92f Mon Sep 17 00:00:00 2001 From: azurepolarbear Date: Tue, 29 Oct 2024 08:37:00 -0500 Subject: [PATCH 4/4] Updates to Point and Wave classes. --- package-lock.json | 8 ++++---- package.json | 2 +- src/main/wave/point.ts | 23 ++++++++++++++++++++--- src/main/wave/wave.ts | 23 ++++++++++++++++++++--- 4 files changed, 45 insertions(+), 11 deletions(-) diff --git a/package-lock.json b/package-lock.json index 59c17fa..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": "file://~/Desktop/npm-test/batpb-genart-2.0.0-rainbow-waves-test-004.tgz", + "@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,9 +35,9 @@ } }, "node_modules/@batpb/genart": { - "version": "2.0.0-rainbow-waves-test-004", - "resolved": "file:../../../../../../../../../Desktop/npm-test/batpb-genart-2.0.0-rainbow-waves-test-004.tgz", - "integrity": "sha512-wr7aUoWF6RlUfhgTULMq7v7J6+ExMwqgyJfGC76AZuT9ouFjNMLpErbua6jPVXemXYbjwBfTXUBIq84mz6Mtsw==", + "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", diff --git a/package.json b/package.json index ec8a281..c6eb1b6 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": "file://~/Desktop/npm-test/batpb-genart-2.0.0-rainbow-waves-test-004.tgz", + "@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/wave/point.ts b/src/main/wave/point.ts index 5d4b40a..2199286 100644 --- a/src/main/wave/point.ts +++ b/src/main/wave/point.ts @@ -21,10 +21,10 @@ * for full license details. */ -import {Coordinate, Point as PointShape} from '@batpb/genart' +import {CanvasRedrawListener, Color, Coordinate, Point as PointShape} from '@batpb/genart' import P5Lib from "p5"; -export class Point { +export class Point implements CanvasRedrawListener { #base: Coordinate = new Coordinate(); #point: PointShape; #theta: number; @@ -36,10 +36,27 @@ export class Point { this.#theta = theta; this.#amplitude = amp; this.#deltaTheta = deltaTheta; + this.#point = new PointShape(); + this.#updatePosition(); + this.#point.stroke = new Color(255, 0, 0); } - #updatePosition(): void { + 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 { diff --git a/src/main/wave/wave.ts b/src/main/wave/wave.ts index 694cd84..7a28a00 100644 --- a/src/main/wave/wave.ts +++ b/src/main/wave/wave.ts @@ -21,17 +21,18 @@ * for full license details. */ -import P5Lib from "p5"; +import P5Lib, {length} from "p5"; import {Point} from "./point"; +import {CanvasRedrawListener, P5Context} from "@batpb/genart"; -export class Wave { +export class Wave implements CanvasRedrawListener { #base: P5Lib.Vector; #length: number; #amplitude: number; #frequency: number; #pointCount: number; #deltaTheta: number; - const #points: Point[] = []; + readonly #points: Point[] = []; constructor(base: P5Lib.Vector, length: number, amplitude: number, frequency: number, pointCount: number) { this.#base = base; @@ -44,6 +45,22 @@ export class Wave { } #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 { } }