Wind speed changes depending on where the wind direction is. #story[1187]

main
Joseph Gardner 9 years ago
parent d0ba7b93e0
commit b0f7c5e734

@ -11,7 +11,7 @@ import java.util.Random;
public class ShiftingWindGenerator implements WindGenerator { public class ShiftingWindGenerator implements WindGenerator {
Bearing baselineBearing; Bearing baselineBearing;
double baseLineSpeed; double baseLineSpeed;
double speedVariance = 4; double speedVariance = 2;
double bearingVariance = 5; // In degrees double bearingVariance = 5; // In degrees
double oscillationVariance = 0.25; double oscillationVariance = 0.25;
double oscillationPeriod = 1e3 * 60 * 1; // In milliseconds double oscillationPeriod = 1e3 * 60 * 1; // In milliseconds
@ -20,7 +20,7 @@ public class ShiftingWindGenerator implements WindGenerator {
double timeOfLastChange = 0; double timeOfLastChange = 0;
double timeSinceLastShift = 0; // Back / veer double timeSinceLastShift = 0; // Back / veer
boolean oscillationLeft = false; boolean anticlockwise = false;
public ShiftingWindGenerator(Bearing baselineBearing, double baseLineSpeed) { public ShiftingWindGenerator(Bearing baselineBearing, double baseLineSpeed) {
this.baselineBearing = baselineBearing; this.baselineBearing = baselineBearing;
@ -56,13 +56,13 @@ public class ShiftingWindGenerator implements WindGenerator {
if (timeSinceLastOscillationReset >= oscillationPeriod) { if (timeSinceLastOscillationReset >= oscillationPeriod) {
timeOfLastOscillationReset = System.currentTimeMillis(); timeOfLastOscillationReset = System.currentTimeMillis();
oscillationLeft = !oscillationLeft; anticlockwise = !anticlockwise;
} }
if (oscillationLeft) { if (anticlockwise) {
newBearing -= degreeChange; newBearing -= degreeChange;
if (newBearing < baselineBearing.degrees() - bearingVariance) { if (newBearing < baselineBearing.degrees() - bearingVariance) {
System.out.println(timeSinceLastOscillationReset); System.out.println(timeSinceLastOscillationReset);
oscillationLeft = !oscillationLeft; anticlockwise = !anticlockwise;
timeOfLastOscillationReset = System.currentTimeMillis(); timeOfLastOscillationReset = System.currentTimeMillis();
} else { } else {
wind.setWindDirection(Bearing.fromDegrees(newBearing % 360)); wind.setWindDirection(Bearing.fromDegrees(newBearing % 360));
@ -71,7 +71,7 @@ public class ShiftingWindGenerator implements WindGenerator {
newBearing += degreeChange; newBearing += degreeChange;
if (newBearing > baselineBearing.degrees() + bearingVariance) { if (newBearing > baselineBearing.degrees() + bearingVariance) {
System.out.println(timeSinceLastOscillationReset); System.out.println(timeSinceLastOscillationReset);
oscillationLeft = !oscillationLeft; anticlockwise = !anticlockwise;
timeOfLastOscillationReset = System.currentTimeMillis(); timeOfLastOscillationReset = System.currentTimeMillis();
} else { } else {
wind.setWindDirection(Bearing.fromDegrees(newBearing % 360)); wind.setWindDirection(Bearing.fromDegrees(newBearing % 360));
@ -83,11 +83,14 @@ public class ShiftingWindGenerator implements WindGenerator {
} }
private void changeWindSpeed(Wind wind) { private void changeWindSpeed(Wind wind) {
double deg = wind.getWindDirection().degrees();
double offset = deg - baselineBearing.degrees();
double newSpeed = offset / bearingVariance * speedVariance + baseLineSpeed;
wind.setWindSpeed(newSpeed);
} }
private void initialiseOscillationDirection() { private void initialiseOscillationDirection() {
oscillationLeft = new Random().nextBoolean(); anticlockwise = new Random().nextBoolean();
timeOfLastOscillationReset = System.currentTimeMillis(); timeOfLastOscillationReset = System.currentTimeMillis();
} }

Loading…
Cancel
Save