Skip to content

Commit

Permalink
adding proper NumberControls, see phetsims/my-solar-system#104
Browse files Browse the repository at this point in the history
  • Loading branch information
AgustinVallejo committed Mar 21, 2023
1 parent bac42e3 commit 315e557
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
4 changes: 4 additions & 0 deletions js/SolarSystemCommonStrings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ type StringsType = {
'clearStringProperty': LinkableProperty<string>;
'path': string;
'pathStringProperty': LinkableProperty<string>;
'scale': string;
'scaleStringProperty': LinkableProperty<string>;
'offscaleMessage': string;
'offscaleMessageStringProperty': LinkableProperty<string>;
'speed': string;
Expand All @@ -48,6 +50,8 @@ type StringsType = {
'restartStringProperty': LinkableProperty<string>;
'massSlider': string;
'massSliderStringProperty': LinkableProperty<string>;
'scaleSlider': string;
'scaleSliderStringProperty': LinkableProperty<string>;
'increase': string;
'increaseStringProperty': LinkableProperty<string>;
'decrease': string;
Expand Down
30 changes: 15 additions & 15 deletions js/view/VectorNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,21 @@ export default class VectorNode extends ArrowNode {

this.tipProperty = new DerivedProperty( [ this.tailProperty, vectorProperty, transformProperty, forceScaleProperty ],
( tail, vector, transform, forceScale ) => {
// forceScale currently goes from -2 to 8, where -2 is scaling down for big vectors ~100 units of force
// and 8 is scaling up for small vectors ~1/100000000 units of force
const magnitudeLog = vector.magnitude ? Math.log10( vector.magnitude / 500 ) : -forceScale;
if ( magnitudeLog > -forceScale + 1 ) {
this.oversizeType = OversizeType.BIGGER;
body.forceOffscaleProperty.value = true;
}
else if ( magnitudeLog < -forceScale - 1 ) {
this.oversizeType = OversizeType.SMALLER;
body.forceOffscaleProperty.value = true;
}
else {
this.oversizeType = OversizeType.NONE;
body.forceOffscaleProperty.value = false;
}
// forceScale currently goes from -2 to 8, where -2 is scaling down for big vectors ~100 units of force
// and 8 is scaling up for small vectors ~1/100000000 units of force
const magnitudeLog = vector.magnitude ? Math.log10( vector.magnitude / 500 ) : -forceScale;
if ( magnitudeLog > -forceScale + 1 ) {
this.oversizeType = OversizeType.BIGGER;
body.forceOffscaleProperty.value = true;
}
else if ( magnitudeLog < -forceScale - 1 ) {
this.oversizeType = OversizeType.SMALLER;
body.forceOffscaleProperty.value = true;
}
else {
this.oversizeType = OversizeType.NONE;
body.forceOffscaleProperty.value = false;
}
const finalPosition = transform.modelToViewDelta( vector.times( 0.05 * Math.pow( 10, forceScale ) ) ).plus( tail );
return finalPosition;
} );
Expand Down
6 changes: 6 additions & 0 deletions solar-system-common-strings_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
"path": {
"value": "Path"
},
"scale": {
"value": "Scale:"
},
"offscaleMessage": {
"value": "Some force vectors might be off-scale"
},
Expand Down Expand Up @@ -51,6 +54,9 @@
"massSlider": {
"value": "Mass Slider"
},
"scaleSlider": {
"value": "Scale Slider"
},
"increase": {
"value": "Increase"
},
Expand Down

0 comments on commit 315e557

Please sign in to comment.