-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathP5.pde
136 lines (104 loc) · 3.41 KB
/
P5.pde
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import peasy.*;
PeasyCam camera;
final int _MAP_SIZE = 150;
final float _MAP_CELL_SIZE = 10f;
boolean _viewmode = false;
boolean _clear = false;
HeightMap map;
PImage image;
float amplitude = random(40f) + 10f;
float dx = random(2f) - 1;
float dz = random(2f) - 1;
float wavelength = amplitude * (10 + random(10f));
float speed = wavelength / (1 + random(5f));
void setup()
{
size(1000, 1000, P3D);
image = loadImage("water_surface.jpg");
camera = new PeasyCam(this, 100);
camera.setMinimumDistance(50);
camera.setMaximumDistance(2000);
camera.setDistance(3000);
camera.rotateX(0.5);
map = new HeightMap(_MAP_SIZE, _MAP_CELL_SIZE);
println(image.width + " : " + image.height);
}
void draw()
{
background(255);
lights();
map.update();
if(_viewmode)
map.presentWired();
else
map.present();
presentAxis();
drawInteractiveInfo();
if(_clear)
{
map.waves.clear();
map.waveArray = new Wave[0];
_clear = false;
}
}
void drawInteractiveInfo()
{
float textSize = 60;
float offsetX = -900;
float offsetZ = -1000;
float offsetY = -900;
int i = 0;
noStroke();
textSize(textSize);
fill(0xff000000);
text("s: sinusoidal wave", offsetX, offsetY + textSize * (++i), offsetZ);
text("r: radial wave", offsetX, offsetY + textSize * (++i), offsetZ);
text("g: gerstner wave", offsetX, offsetY + textSize * (++i), offsetZ);
text("c: change viewmode", offsetX, offsetY + textSize * (++i), offsetZ);
text("i: reset", offsetX, offsetY + textSize * (++i), offsetZ);
text("1: decreases the amplitude", offsetX, offsetY + textSize * (++i), offsetZ);
text("2: increase the amplitude", offsetX, offsetY + textSize * (++i), offsetZ);
text("3: decreases the wavelength", offsetX, offsetY + textSize * (++i), offsetZ);
text("4: increase the wavelength", offsetX, offsetY + textSize * (++i), offsetZ);
text("5: decreases the speed", offsetX, offsetY + textSize * (++i), offsetZ);
text("6: increase the speed", offsetX, offsetY + textSize * (++i), offsetZ);
i = 0;
text ("Amplitude value: " + amplitude, offsetX -offsetY, offsetY + textSize* (++i), offsetZ);
text ("Wavelength value: " + wavelength , offsetX -offsetY, offsetY + textSize* (++i), offsetZ);
text ("Speed value: " + speed, offsetX -offsetY, offsetY + textSize* (++i), offsetZ);
}
void keyPressed()
{
if(key == 's' || key == 'S')
map.addWave(new WaveDirectional(amplitude, new PVector(dx, 0, dz), wavelength, speed));
if(key == 'r' || key == 'R')
map.addWave(new WaveRadial(amplitude, new PVector(dx * (_MAP_SIZE * _MAP_CELL_SIZE / 2f), 0, dz * (_MAP_SIZE * _MAP_CELL_SIZE / 2f)), wavelength, speed));
if(key == 'g' || key == 'G')
map.addWave(new WaveGerstner(amplitude, new PVector(dx, 0, dz), wavelength, speed));
if(key == 'c' || key == 'C')
_viewmode = !_viewmode;
if(key == 'i' || key == 'I')
_clear = true;
if (key == '1')
amplitude = amplitude - 5f;
if (key == '2')
amplitude = amplitude + 5f;
if (key == '3')
wavelength = wavelength - 5f;
if (key == '4')
wavelength = wavelength + 5f;
if (key == '5')
speed = speed - 5f;
if (key == '6')
speed = speed + 5f;
}
void presentAxis()
{
float axisSize = _MAP_SIZE * 2f;
stroke(0xffff0000);
line(0, 0, 0, axisSize, 0, 0);
stroke(0xff00ff00);
line(0, 0, 0, 0, -axisSize, 0);
stroke(0xff0000ff);
line(0, 0, 0, 0, 0, axisSize);
}