phetsims / color-vision

"Color Vision" is an educational simulation in HTML5, by PhET Interactive Simulations.
http://phet.colorado.edu/en/simulation/color-vision
GNU General Public License v3.0
1 stars 7 forks source link

Add code comments within the FlashlightNode constructor #37

Closed samreid closed 10 years ago

samreid commented 10 years ago

Here is the FlashlightNode constructor. Would be good to add some inner line comments describing what the shape looks like, why the flashlight image is positioned where it is, which direction it is pointing, etc.

  function FlashlightNode( rotation, color, options ) {

    Node.call( this, { rotation: rotation } );

    var scale = 0.8;
    var flashlightImage = new Image( flashlight,
      {
        scale: scale,
        left: this.centerX,
        centerY: this.centerY
      } );

    var startX = flashlightImage.left + 15;
    var centerY = flashlightImage.centerY + 0.5;
    var dx = 20 / 0.12 * scale;
    var dy = 3 / 0.12 * scale;
    var beamShape = new Shape().
      moveTo( startX, centerY + dy ).
      lineTo( startX - dx, centerY + dy * 2 ).
      lineTo( startX - dx, centerY - dy * 2 ).
      lineTo( startX, centerY - dy ).
      close();

    this.addChild( new Path( beamShape, { fill: color } ) );
    this.addChild( flashlightImage );

    this.mutate( options );
  }
aaronsamuel137 commented 10 years ago

Comments updated. Assigning to @samreid for review

samreid commented 10 years ago

Looks good, thanks! Closing.