Skip to content

Commit

Permalink
Add aspect ratio updates for waves.
Browse files Browse the repository at this point in the history
  • Loading branch information
azurepolarbear committed Dec 28, 2024
1 parent 85e4248 commit ebe1065
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
9 changes: 3 additions & 6 deletions src/main/wave-testing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ export class WaveTesting extends WaveScreen {
};

this.#horizontalWave = new Wave(hConfig);

console.log(this.#horizontalWave);
this.addRedrawListener(this.#horizontalWave);

const vConfig: WaveConfig = {
coordinateMode: CoordinateMode.RATIO,
Expand All @@ -54,8 +53,7 @@ export class WaveTesting extends WaveScreen {
};

this.#verticalWave = new Wave(vConfig);

console.log(this.#verticalWave);
this.addRedrawListener(this.#verticalWave);

const dConfig: WaveConfig = {
coordinateMode: CoordinateMode.RATIO,
Expand All @@ -64,8 +62,7 @@ export class WaveTesting extends WaveScreen {
};

this.#diagonalWave = new Wave(dConfig);

console.log(this.#diagonalWave);
this.addRedrawListener(this.#diagonalWave);
}

public draw(): void {
Expand Down
19 changes: 13 additions & 6 deletions src/main/wave/wave.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

import P5Lib from 'p5';

import { CanvasContext, CoordinateMode, P5Context } from '@batpb/genart';
import { CanvasContext, CanvasRedrawListener, CoordinateMode, P5Context } from '@batpb/genart';
import { WaveEdge } from './wave-edge';

export interface WaveConfig {
Expand All @@ -32,18 +32,27 @@ export interface WaveConfig {
edgeB: { top: P5Lib.Vector; bottom: P5Lib.Vector; };
}

export class Wave {
export class Wave implements CanvasRedrawListener {
readonly #EDGE_A: WaveEdge;
readonly #EDGE_B: WaveEdge;

#rotation: number = 0;

constructor(config: WaveConfig) {
public constructor(config: WaveConfig) {
this.#EDGE_A = new WaveEdge(config.edgeA.top, config.edgeA.bottom, config.coordinateMode);
this.#EDGE_B = new WaveEdge(config.edgeB.top, config.edgeB.bottom, config.coordinateMode);
this.#updateRotation();
}

public canvasRedraw(): void {
this.#EDGE_A.remap();
this.#EDGE_B.remap();
this.#updateRotation();
}

public draw(): void {

Check failure on line 53 in src/main/wave/wave.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Unexpected empty method 'draw'

Check failure on line 53 in src/main/wave/wave.ts

View workflow job for this annotation

GitHub Actions / build (20.x)

Unexpected empty method 'draw'

Check failure on line 53 in src/main/wave/wave.ts

View workflow job for this annotation

GitHub Actions / build (22.x)

Unexpected empty method 'draw'
}

#updateRotation(): void {
const p5: P5Lib = P5Context.p5;
const center_A: P5Lib.Vector = this.#EDGE_A.center;
Expand All @@ -52,12 +61,10 @@ export class Wave {
p5.push();
p5.translate(center_A.x, center_A.y);
this.#rotation = translated_B.heading();
console.log(this.#rotation);
console.log(P5Lib.Vector.angleBetween(this.#EDGE_A.center, this.#EDGE_B.center));
p5.pop();
}

debug_drawFrame(border: number): void {
public debug_drawFrame(border: number): void {
const p5: P5Lib = P5Context.p5;
p5.stroke(border);
p5.strokeWeight(CanvasContext.defaultStroke);
Expand Down

0 comments on commit ebe1065

Please sign in to comment.