Skip to content

Commit

Permalink
Merge branch 'rainbow-waves'
Browse files Browse the repository at this point in the history
  • Loading branch information
azurepolarbear committed Nov 3, 2024
2 parents 6bac5c3 + 06b5465 commit d296527
Show file tree
Hide file tree
Showing 7 changed files with 247 additions and 13 deletions.
12 changes: 6 additions & 6 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
42 changes: 42 additions & 0 deletions src/main/sketch-screen.ts
Original file line number Diff line number Diff line change
@@ -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');
}
}
34 changes: 28 additions & 6 deletions src/main/sketch.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// noinspection DuplicatedCode

/*
* Copyright (C) 2015-2024 brittni and the polar bear LLC.
*
Expand All @@ -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();
};
}

Expand Down
65 changes: 65 additions & 0 deletions src/main/wave/point.ts
Original file line number Diff line number Diff line change
@@ -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);
}
}
66 changes: 66 additions & 0 deletions src/main/wave/wave.ts
Original file line number Diff line number Diff line change
@@ -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 {
}
}
39 changes: 39 additions & 0 deletions src/to-do.js
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit d296527

Please sign in to comment.