Skip to content

Commit

Permalink
Improve types, see #401
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed Oct 11, 2021
1 parent 82308da commit 6fc2589
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 7 deletions.
2 changes: 2 additions & 0 deletions js/common/model/BendingLightModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ abstract class BendingLightModel {
*/
clearModel() {
for ( let i = 0; i < this.rays.length; i++ ) {

// @ts-ignore createObservableArray
this.rays[ i ].particles.clear();
}
this.rays.length = 0;
Expand Down
5 changes: 3 additions & 2 deletions js/common/model/LightRay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import Shape from '../../../../kite/js/Shape.js';
import Color from '../../../../scenery/js/util/Color.js';
import bendingLight from '../../bendingLight.js';
import BendingLightConstants from '../BendingLightConstants.js';
import WaveParticle from './WaveParticle.js';

// constants
/**
Expand All @@ -32,7 +33,7 @@ const makeFinite = ( vector: Vector2 ) => {

class LightRay {
extendBackwards: boolean;
color: any;
color: Color;
waveWidth: number;
trapeziumWidth: number;
tip: Vector2;
Expand All @@ -44,7 +45,7 @@ class LightRay {
numWavelengthsPhaseOffset: number;
extend: boolean;
vectorForm: Vector2;
particles: any;
particles: WaveParticle[];
time: number;
rayType: string;
unitVector: Vector2;
Expand Down
6 changes: 3 additions & 3 deletions js/common/model/WaveParticle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ class WaveParticle {
private readonly position: Vector2;
private readonly width: number;
private readonly color: Color;
private readonly angle: number;
private readonly height: number;
private readonly particleGradientColor: Color;
readonly angle: number;
readonly height: number;
readonly particleGradientColor: Color;

/**
* @param {Vector2} position - position of wave particle
Expand Down
2 changes: 1 addition & 1 deletion js/intro/model/IntroModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ class IntroModel extends BendingLightModel {

// Changing the wave particle position within the wave particle phase
for ( let j = 0; j < waveParticles.length; j++ ) {
const particle = waveParticles.get( j );
const particle = waveParticles[j];
particle.setX( tailX + ( directionVector.x * ( ( j * wavelength ) + phaseDiff ) ) );
particle.setY( tailY + ( directionVector.y * ( ( j * wavelength ) + phaseDiff ) ) );
}
Expand Down
4 changes: 3 additions & 1 deletion js/intro/view/WaveCanvasNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class WaveCanvasNode extends CanvasNode {
context.clip();
}

const particle = ray.particles.get( 0 );
const particle = ray.particles[ 0 ];

// Set the origin at the beginning of the particle
context.translate(
Expand All @@ -78,10 +78,12 @@ class WaveCanvasNode extends CanvasNode {
const wavelength = this.modelViewTransform.modelToViewDeltaX( particle.height );

// Fill the background with the dark color, in the entire clip area
// @ts-ignore
context.fillStyle = particle.particleGradientColor;
context.fillRect( -1000, -1000, 2000, 2000 );

// Set up the color for the wave crests
// @ts-ignore
context.fillStyle = particle.color;

// Render each crest, but we don't need as many wavelengths for the incoming light
Expand Down
3 changes: 3 additions & 0 deletions js/intro/view/WaveWebGLNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,11 @@ class WavePainter {
);

// light ray color
// @ts-ignore
const red = lightRay.color.r / 255;
// @ts-ignore
const green = lightRay.color.g / 255;
// @ts-ignore
const blue = lightRay.color.b / 255;

gl.bindBuffer( gl.ARRAY_BUFFER, this.vertexBuffer );
Expand Down

0 comments on commit 6fc2589

Please sign in to comment.