Project

General

Profile

Download (2.78 KB) Statistics
| Branch: | Revision:

examples / src / main / java / org / distorted / examples / wind / WindGust.java @ 0339e04e

1 318dd77b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 Leszek Koltunski                                                               //
3
//                                                                                               //
4 71c8884f Leszek Koltunski
// This file is part of Distorted.                                                               //
5 318dd77b Leszek Koltunski
//                                                                                               //
6 71c8884f Leszek Koltunski
// Distorted is free software: you can redistribute it and/or modify                             //
7 318dd77b Leszek Koltunski
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11 71c8884f Leszek Koltunski
// Distorted is distributed in the hope that it will be useful,                                  //
12 318dd77b Leszek Koltunski
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17 71c8884f Leszek Koltunski
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18 318dd77b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
19
20
package org.distorted.examples.wind;
21
22
import java.util.Random;
23
24
///////////////////////////////////////////////////////////////////////////////////////////////////
25
26
class WindGust
27
  {
28
  private static final long TIME_PERIOD = 1000;
29
  private int mAvgWind;
30
  private boolean mBlowingNow;
31
  private long mLastTime;
32
  private static Random mRnd = new Random();
33
34
  WindGust()
35
    {
36
    mAvgWind = 0;
37
    mBlowingNow = false;
38
    mLastTime = 0;
39
    }
40
41
///////////////////////////////////////////////////////////////////////////////////////////////////
42
43
  void setAverageWind(int wind)
44
    {
45
    mAvgWind = wind;
46
    }
47
48
///////////////////////////////////////////////////////////////////////////////////////////////////
49
50
  boolean isWindBlowingNow(long currTime)
51
    {
52
    if( mLastTime>0 )
53
      {
54
      int lastPeriod = (int)(mLastTime/TIME_PERIOD);
55
      int currPeriod = (int)( currTime/TIME_PERIOD);
56
57
      if( currPeriod>lastPeriod ) mBlowingNow=(mRnd.nextInt(100)<=mAvgWind);
58
      }
59
60
    mLastTime = currTime;
61
62
    return mBlowingNow;
63
    }
64
  }