Skip to content

Commit

Permalink
Add initial movement to Point and Wave classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
azurepolarbear committed Dec 28, 2024
1 parent e581747 commit 40aced8
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/main/wave-testing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,14 @@ export class WaveTesting extends WaveScreen {

this.#horizontalWave.draw();
this.#horizontalWave.debug_drawFrame(255);
this.#horizontalWave.move();

this.#verticalWave.draw();
this.#verticalWave.debug_drawFrame(255);
this.#verticalWave.move();

this.#diagonalWave.draw();
this.#diagonalWave.debug_drawFrame(255);
this.#diagonalWave.move();
}
}
28 changes: 25 additions & 3 deletions src/main/wave/point/point.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ export interface PointConfig {
waveRatio_end: number;
base: P5Lib.Vector;
diameter: number;
theta: number;
deltaTheta: number;
amplitude: number;
}

/**
Expand All @@ -40,15 +43,21 @@ export class Point {
#waveRatio_start: number;
#waveRatio_end: number;
#base: P5Lib.Vector;
#position: P5Lib.Vector;
#diameter: number;
// #theta: number = 0;
// #deltaTheta: number = 0.01;
#theta: number;
#deltaTheta: number;
#amplitude: number;

public constructor(config: PointConfig) {
this.#base = config.base;
this.#position = this.#base.copy();
this.#diameter = config.diameter;
this.#waveRatio_start = config.waveRatio_start;
this.#waveRatio_end = config.waveRatio_end;
this.#theta = config.theta;
this.#deltaTheta = config.deltaTheta;
this.#amplitude = config.amplitude;
}

public get waveRatio_start(): number {
Expand All @@ -72,7 +81,12 @@ export class Point {
p5.fill(255, 0, 0);
p5.strokeWeight(CanvasContext.defaultStroke);
p5.stroke(0, 0, 255);
p5.ellipse(this.#base.x, this.#base.y, this.#diameter, this.#diameter);
p5.ellipse(this.#position.x, this.#position.y, this.#diameter, this.#diameter);
}

public move(): void {
this.#theta += this.#deltaTheta;
this.#updatePosition();
}

public updateBase(base: P5Lib.Vector): void {
Expand All @@ -82,4 +96,12 @@ export class Point {
public updateDiameter(diameter: number): void {
this.#diameter = diameter;
}

#updatePosition(): void {
this.#position.set(this.#base.x, this.#calculateY());
}

#calculateY(): number {
return (this.#base.y + (this.#amplitude * Math.sin(this.#theta)));
}
}
11 changes: 10 additions & 1 deletion src/main/wave/wave.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ export class Wave implements CanvasRedrawListener {
p5.pop();
}

public move(): void {
this.#points.forEach((point: Point): void => {
point.move();

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

View workflow job for this annotation

GitHub Actions / build (18.x)

Expected indentation of 12 spaces but found 11

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

View workflow job for this annotation

GitHub Actions / build (20.x)

Expected indentation of 12 spaces but found 11

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

View workflow job for this annotation

GitHub Actions / build (22.x)

Expected indentation of 12 spaces but found 11
});
}

#updateRotation(): void {
const p5: P5Lib = P5Context.p5;
const center_A: P5Lib.Vector = this.#EDGE_A.center;
Expand Down Expand Up @@ -104,7 +110,10 @@ export class Wave implements CanvasRedrawListener {
waveRatio_start: waveRatio_start,
waveRatio_end: waveRatio_end,
base: base,
diameter: diameter
diameter: diameter,
theta: 0,
deltaTheta: 0.005,
amplitude: 5
}

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

View workflow job for this annotation

GitHub Actions / build (18.x)

Missing semicolon

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

View workflow job for this annotation

GitHub Actions / build (20.x)

Missing semicolon

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

View workflow job for this annotation

GitHub Actions / build (22.x)

Missing semicolon

this.#points.push(new Point(pointConfig));
Expand Down

0 comments on commit 40aced8

Please sign in to comment.