Skip to content

Commit

Permalink
TS conversion step, see #160
Browse files Browse the repository at this point in the history
  • Loading branch information
jbphet committed Mar 23, 2022
1 parent 68dacaf commit 088f40f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 25 deletions.
8 changes: 4 additions & 4 deletions js/demo/sim-like-components/model/Ball.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import { Color } from '../../../../../scenery/js/imports.js';
import tambo from '../../../tambo.js';

class Ball {
private readonly radius: number;
private readonly color: Color;
private readonly positionProperty: Vector2Property;
private readonly velocityProperty: Vector2Property;
public readonly radius: number;
public readonly color: Color;
public readonly positionProperty: Vector2Property;
public readonly velocityProperty: Vector2Property;
private readonly bounceEmitter: Emitter<[string]>;

constructor( radius: number, color: Color, initialPosition: Vector2, initialVelocity: Vector2 ) {
Expand Down
32 changes: 11 additions & 21 deletions js/demo/sim-like-components/model/BoxOfBalls.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
// Copyright 2018-2022, University of Colorado Boulder

// @ts-nocheck

/**
* BoxOfBalls is a model of a box containing moving balls that bounce off the walls.
*/

import createObservableArray from '../../../../../axon/js/createObservableArray.js';
import createObservableArray, { ObservableArray } from '../../../../../axon/js/createObservableArray.js';
import dotRandom from '../../../../../dot/js/dotRandom.js';
import Vector2 from '../../../../../dot/js/Vector2.js';
import { Shape } from '../../../../../kite/js/imports.js';
Expand All @@ -28,13 +26,10 @@ const createRandomColor = () => {
};

class BoxOfBalls {
private readonly box: Shape;
private readonly balls: ObservableArray<Ball>;

/**
* @param {number} width - in centimeters
* @param {number} height - in centimeters
* @constructor
*/
constructor( width, height ) {
constructor( width: number, height: number ) {

// @public (read-only) {Shape.rect} - the bounding box
this.box = Shape.rect( 50, 0, width, height );
Expand All @@ -44,10 +39,9 @@ class BoxOfBalls {
}

/**
* add a ball with random size, color, position, and velocity
* @public
* Add a ball with random size, color, position, and velocity.
*/
addRandomBall() {
public addRandomBall() {

let xVelocity = MIN_X_OR_Y_VELOCITY + dotRandom.nextDouble() * ( MAX_X_OR_Y_VELOCITY - MIN_X_OR_Y_VELOCITY );
xVelocity = dotRandom.nextBoolean() ? xVelocity : -xVelocity;
Expand All @@ -66,19 +60,17 @@ class BoxOfBalls {
}

/**
* remove a ball
* @public
* Remove a ball.
*/
removeABall() {
public removeABall() {
this.balls.pop();
}

/**
* step function to move and bounce the balls
* @param {number} dt - time step, in seconds
* @public
* @param dt - time step, in seconds
*/
step( dt ) {
public step( dt: number ) {
const boxBounds = this.box.bounds;
this.balls.forEach( ball => {
const positionBeforeMotion = ball.positionProperty.value;
Expand Down Expand Up @@ -112,12 +104,10 @@ class BoxOfBalls {

/**
* restore initial state
* @public
*/
reset() {
public reset() {
this.balls.reset();
}

}

tambo.register( 'BoxOfBalls', BoxOfBalls );
Expand Down

0 comments on commit 088f40f

Please sign in to comment.