Skip to content

Commit

Permalink
small bug fix and name change with resistor dots, #50 #62
Browse files Browse the repository at this point in the history
  • Loading branch information
zepumph committed Jul 18, 2017
1 parent d564dea commit 7011d0a
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions js/ohms-law/view/ResistorNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@ define( function( require ) {
var Util = require( 'DOT/Util' );

// constants
var WIRE_WIDTH = OhmsLawConstants.WIRE_WIDTH / 2.123; // empirically determined
var WIRE_HEIGHT = OhmsLawConstants.WIRE_HEIGHT / 2.75; // empirically determined
var RESISTOR_WIDTH = OhmsLawConstants.WIRE_WIDTH / 2.123; // empirically determined
var RESISTOR_HEIGHT = OhmsLawConstants.WIRE_HEIGHT / 2.75; // empirically determined
var PERSPECTIVE_FACTOR = 0.3; // multiplier that controls the width of the ellipses on the ends of the wire
var DOT_RADIUS = 2;
var DOT_POSITION_RANDOMIZATION_FACTOR = 12; // empirically determined
var AREA_PER_DOT = 40; // adjust this to control the density of the dots
var MAX_WIDTH_INCLUDING_ROUNDED_ENDS = WIRE_WIDTH + 2 * WIRE_HEIGHT * PERSPECTIVE_FACTOR;
var MAX_WIDTH_INCLUDING_ROUNDED_ENDS = RESISTOR_WIDTH + RESISTOR_HEIGHT * PERSPECTIVE_FACTOR;

var BODY_FILL_GRADIENT = new LinearGradient( 0, -WIRE_HEIGHT / 2, 0, WIRE_HEIGHT / 2 ) // For 3D effect on the wire.
var BODY_FILL_GRADIENT = new LinearGradient( 0, -RESISTOR_HEIGHT / 2, 0, RESISTOR_HEIGHT / 2 ) // For 3D effect on the wire.
.addColorStop( 0, '#F00' )
.addColorStop( 0.266, '#FFF' )
.addColorStop( 0.412, '#FCFCFC' )
.addColorStop( 1, '#F00' );

var DOT_GRID_ROWS = Util.roundSymmetric( WIRE_HEIGHT / Math.sqrt( AREA_PER_DOT ) );
var DOT_GRID_COLUMNS = Util.roundSymmetric( WIRE_WIDTH / Math.sqrt( AREA_PER_DOT ) );
var DOT_GRID_ROWS = Util.roundSymmetric( RESISTOR_HEIGHT / Math.sqrt( AREA_PER_DOT ) );
var DOT_GRID_COLUMNS = Util.roundSymmetric( RESISTOR_WIDTH / Math.sqrt( AREA_PER_DOT ) );
var MAX_DOTS = DOT_GRID_COLUMNS * DOT_GRID_ROWS;

// Function to map resistance to number of dots
Expand All @@ -59,26 +59,26 @@ define( function( require ) {
Node.call( this );

// Body of the wire
var bodyPath = new Path( new Shape().moveTo( -WIRE_WIDTH / 2, WIRE_HEIGHT / 2 )
.horizontalLineToRelative( WIRE_WIDTH )
.ellipticalArc( WIRE_WIDTH / 2, 0, PERSPECTIVE_FACTOR * WIRE_HEIGHT / 2, WIRE_HEIGHT / 2, 0, Math.PI / 2, 3 * Math.PI / 2, true )
.horizontalLineToRelative( -WIRE_WIDTH ), {
var bodyPath = new Path( new Shape().moveTo( -RESISTOR_WIDTH / 2, RESISTOR_HEIGHT / 2 )
.horizontalLineToRelative( RESISTOR_WIDTH )
.ellipticalArc( RESISTOR_WIDTH / 2, 0, PERSPECTIVE_FACTOR * RESISTOR_HEIGHT / 2, RESISTOR_HEIGHT / 2, 0, Math.PI / 2, 3 * Math.PI / 2, true )
.horizontalLineToRelative( -RESISTOR_WIDTH ), {
stroke: 'black',
fill: BODY_FILL_GRADIENT,
tandem: tandem.createTandem( 'bodyPath' )
} );
this.addChild( bodyPath );

// Cap/end of the wire
var endPath = new Path( Shape.ellipse( -WIRE_WIDTH / 2, 0, WIRE_HEIGHT * PERSPECTIVE_FACTOR / 2, WIRE_HEIGHT / 2 ), {
var endPath = new Path( Shape.ellipse( -RESISTOR_WIDTH / 2, 0, RESISTOR_HEIGHT * PERSPECTIVE_FACTOR / 2, RESISTOR_HEIGHT / 2 ), {
stroke: 'black',
fill: '#ff9f9f',
tandem: tandem.createTandem( 'endPath' )
} );
this.addChild( endPath );

// Short stub of wire near the cap of wire
var stubWirePath = new Path( new Shape().moveTo( 5 - WIRE_WIDTH / 2, 0 ).horizontalLineToRelative( -15 ), {
var stubWirePath = new Path( new Shape().moveTo( 5 - RESISTOR_WIDTH / 2, 0 ).horizontalLineToRelative( -15 ), {
stroke: '#000',
lineWidth: 10,
tandem: tandem.createTandem( 'stubWirePath' )
Expand All @@ -99,7 +99,7 @@ define( function( require ) {
var centerX = i * ( MAX_WIDTH_INCLUDING_ROUNDED_ENDS / DOT_GRID_COLUMNS ) -
MAX_WIDTH_INCLUDING_ROUNDED_ENDS / 2 +
(phet.joist.random.nextDouble() - 0.5 ) * DOT_POSITION_RANDOMIZATION_FACTOR;
var centerY = j * ( WIRE_HEIGHT / DOT_GRID_ROWS ) - WIRE_HEIGHT / 2 +
var centerY = j * ( RESISTOR_HEIGHT / DOT_GRID_ROWS ) - RESISTOR_HEIGHT / 2 +
( phet.joist.random.nextDouble() - 0.5 ) * DOT_POSITION_RANDOMIZATION_FACTOR;
var dot = new Circle( DOT_RADIUS, {
fill: 'black',
Expand All @@ -117,10 +117,10 @@ define( function( require ) {

// Clip the dots that are shown to only include those inside the wire (including the wireEnd)
dotsNode.clipArea = bodyPath.shape.ellipticalArc(
-WIRE_WIDTH / 2,
-RESISTOR_WIDTH / 2,
0,
PERSPECTIVE_FACTOR * WIRE_HEIGHT / 2,
WIRE_HEIGHT / 2,
PERSPECTIVE_FACTOR * RESISTOR_HEIGHT / 2,
RESISTOR_HEIGHT / 2,
0,
3 * Math.PI / 2,
Math.PI / 2,
Expand All @@ -130,7 +130,7 @@ define( function( require ) {
resistanceProperty.link( function( resistance ) {
var numDotsToShow = RESISTANCE_TO_NUM_DOTS( resistance );
dotsNode.children.forEach( function( dot, index ) {
dot.visible = index < numDotsToShow;
dot.setVisible( index < numDotsToShow);
} );
} );

Expand Down

0 comments on commit 7011d0a

Please sign in to comment.