-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWindForce.java
More file actions
68 lines (62 loc) · 1.42 KB
/
WindForce.java
File metadata and controls
68 lines (62 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import processing.core.PApplet;
import processing.core.PVector;
public class WindForce
{
/** The parent PApplet that we will render ourselves onto. */
private PApplet p5;
/** Force of the wind */
private PVector force;
/** Varying time which will affect the force */
private float time;
/** Size of the time increment affecting the speed of change.*/
private float stepSize;
WindForce(PApplet p) {
this.p5 = p;
time = p5.random(PApplet.TWO_PI);
force = new PVector(0,0);
stepSize = 0.004f;
}
/**
* Increment the force in time.
*/
public void step()
{
time += stepSize;
force.x = Constants.maxWindForceMagnitude*PApplet.sin(time);
}
/**
* Obtain the lateral wind force.
* @return Wind force PVector
*/
public PVector getForce()
{
return force.get();
}
/** Draw an arrow.
* @param x1 Start x-coord
* @param y1 Start y-coord
* @param x2 End x-coord
* @param y2 End y-coord
*/
private void arrow(float x1, float y1, float x2, float y2) {
p5.line(x1, y1, x2, y2);
p5.pushMatrix();
p5.translate(x2, y2);
float a = PApplet.atan2(x1-x2, y2-y1);
p5.rotate(a);
p5.line(0, 0, -6, -6);
p5.line(0, 0, 6, -6);
p5.popMatrix();
}
/** Draw the wind force as an arrow */
public void draw() {
p5.strokeWeight(3.0f);
p5.stroke(0, 150, 0);
float x1 = p5.width - 75.0f;
float y1 = 10.0f;
float x2 = x1 + 300.0f*force.x;
float y2 = y1;
arrow(x1, y1, x2, y2);
p5.noStroke();
}
}