Skip to content

Commit

Permalink
RightAngleArrow inherits from Path, #51
Browse files Browse the repository at this point in the history
  • Loading branch information
zepumph committed Jun 25, 2017
1 parent 56c3397 commit cde20a4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
15 changes: 9 additions & 6 deletions js/ohms-law/view/OhmsLawScreenView.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ define( function( require ) {

ScreenView.call( this );

// Node of ohm's law equation. Layout is hardwired, see FormulaNode.
var formulaNode = new FormulaNode( model.currentProperty, model.voltageProperty, model.resistanceProperty, {
pickable: false
} );

// Add the formula first
this.addChild( formulaNode );


// Circuit node with readout node
var wireBox = new WireBox( model.voltageProperty, model.resistanceProperty, model.currentProperty, {
pickable: false,
Expand All @@ -46,12 +55,6 @@ define( function( require ) {
} );
this.addChild( wireBox );

// Node of ohm's law equation. Layout is hardwired, see FormulaNode.
var formulaNode = new FormulaNode( model.currentProperty, model.voltageProperty, model.resistanceProperty, {
pickable: false
} );
this.addChild( formulaNode );

// Create and add control panel with sliders.
var controlPanel = new ControlPanel( model.voltageProperty, model.resistanceProperty );
controlPanel.right = this.layoutBounds.width - 25; // empirically determined
Expand Down
17 changes: 9 additions & 8 deletions js/ohms-law/view/RightAngleArrow.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ define( function( require ) {
// modules
var inherit = require( 'PHET_CORE/inherit' );
var Matrix3 = require( 'DOT/Matrix3' );
var Node = require( 'SCENERY/nodes/Node' );
var Path = require( 'SCENERY/nodes/Path' );
var PhetColorScheme = require( 'SCENERY_PHET/PhetColorScheme' );
var Shape = require( 'KITE/Shape' );
Expand All @@ -40,31 +39,33 @@ define( function( require ) {
* @constructor
*/
function RightAngleArrow( currentProperty, options ) {

Node.call( this );
var self = this;

// create the shape of the arrow
var arrowShape = new Shape().polygon( POINTS );
var arrowPath = new Path( arrowShape, {

Path.call( this, arrowShape, {
stroke: '#000',
fill: PhetColorScheme.RED_COLORBLIND,
lineWidth: 0.2
} );
this.addChild( arrowPath );

// Present for the lifetime of the simulation
currentProperty.link( function( current ) {
currentProperty.lazyLink( function( current) {

// Scale the arrows based on the value of the current.
// Exponential scaling algorithm. Linear makes the changes too big.
var scale = Math.pow( ( current * 0.1 ), 0.7 );
arrowPath.matrix = Matrix3.scale( scale );

// TODO: use scale instead of overwriting the matrix each time the current changes
self.matrix = Matrix3.scale( scale );
self.mutate( options );
} );

this.mutate( options );
}

ohmsLaw.register( 'RightAngleArrow', RightAngleArrow );

return inherit( Node, RightAngleArrow );
return inherit( Path, RightAngleArrow );
} );

0 comments on commit cde20a4

Please sign in to comment.