Skip to content

Commit

Permalink
Constrain amplitude and diameter for large points.
Browse files Browse the repository at this point in the history
  • Loading branch information
azurepolarbear committed Dec 28, 2024
1 parent 0b3d019 commit 27499c5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/main/wave-testing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class WaveTesting extends WaveScreen {

const hConfig: WaveConfig = {
coordinateMode: CoordinateMode.RATIO,
edgeA: { top: p5.createVector(0, 0.4), bottom: p5.createVector(0, 0.6) },
edgeA: { top: p5.createVector(0, 0.3), bottom: p5.createVector(0, 0.7) },
edgeB: { top: p5.createVector(1, 0.4), bottom: p5.createVector(1, 0.6) }
};

Expand Down
8 changes: 4 additions & 4 deletions src/main/wave/wave-categories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
*/

export enum PointSize {
SMALL = 'small',
MEDIUM = 'medium',
LARGE = 'large',
MIXED = 'mixed'
SMALL = 'small', // 1 / 250 - 1 / 75
MEDIUM = 'medium', // 1 / 100 - 1 / 15
LARGE = 'large', // 1 / 20 - 1 / 4
MIXED = 'mixed' // 1 / 250 - 1 / 4
}

export enum WaveDensity {
Expand Down
25 changes: 20 additions & 5 deletions src/main/wave/wave.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export class Wave implements CanvasRedrawListener {

#buildPoints(): void {
const p5: P5Lib = P5Context.p5;
const pointTotal: number = 50;
const pointTotal: number = 4;
const data: WaveData = this.#getWaveData();
const start: P5Lib.Vector = p5.createVector(0, 0);
const end: P5Lib.Vector = p5.createVector(data.length, 0);
Expand All @@ -108,10 +108,17 @@ export class Wave implements CanvasRedrawListener {
const waveRatio_end: number = (i + 1) / pointTotal;
const waveRatio_center: number = (waveRatio_start + waveRatio_end) / 2;
const ratioLen: number = waveRatio_end - waveRatio_start;
const diameter: number = data.length * ratioLen;
let diameter: number = data.length * ratioLen;
const base: P5Lib.Vector = P5Lib.Vector.lerp(start, end, waveRatio_center);
const pointTheta: number = theta + (waveRatio_center * (Math.PI * 2));
const amplitude: number = p5.map(waveRatio_center, 0, 1, data.amplitude_A, data.amplitude_B) - (diameter / 2.0);
const amplitudeMap: number = p5.map(waveRatio_center, 0, 1, data.amplitude_A, data.amplitude_B);
let amplitude: number = amplitudeMap - (diameter / 2.0);

if (Math.ceil(amplitude) < 0) {
console.log('amplitude is negative');
amplitude = 0;
diameter = amplitudeMap * 2;
}

const pointConfig: PointConfig = {
waveRatio_start: waveRatio_start,
Expand All @@ -134,9 +141,17 @@ export class Wave implements CanvasRedrawListener {
const end: P5Lib.Vector = p5.createVector(data.length, 0);

this.#points.forEach((point: Point): void => {
const diameter: number = data.length * point.getWaveRatioLength();
let diameter: number = data.length * point.getWaveRatioLength();
const base: P5Lib.Vector = P5Lib.Vector.lerp(start, end, point.getWaveRatioCenter());
const amplitude: number = p5.map(point.getWaveRatioCenter(), 0, 1, data.amplitude_A, data.amplitude_B) - (diameter / 2.0);
const amplitudeMap: number = p5.map(point.getWaveRatioCenter(), 0, 1, data.amplitude_A, data.amplitude_B);
let amplitude: number = amplitudeMap - (diameter / 2.0);

if (Math.ceil(amplitude) < 0) {
console.log('amplitude is negative');
amplitude = 0;
diameter = amplitudeMap * 2;
}

point.updateBase(base);
point.updateDiameter(diameter);
point.updateAmplitude(amplitude);
Expand Down

0 comments on commit 27499c5

Please sign in to comment.