-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
186 lines (144 loc) · 6.27 KB
/
index.html
File metadata and controls
186 lines (144 loc) · 6.27 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
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="Mark Otto, Jacob Thornton, and Bootstrap contributors">
<meta name="generator" content="Hugo 0.79.0">
<title>Starter Template · Bootstrap v5.0</title>
<link rel="canonical" href="https://getbootstrap.com/docs/5.0/examples/starter-template/">
<script
type="text/javascript"
src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.1.9/p5.js"
></script>
<!-- Bootstrap core CSS -->
<link href="../assets/dist/css/bootstrap.min.css" rel="stylesheet">
<!-- Bootstrap customCSS -->
<link href="../assets/dist/css/custom.css" rel="stylesheet">
<style>
</style>
<!-- Custom styles for this template -->
<link href="starter-template.css" rel="stylesheet">
</head>
<body>
<nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top">
<div class="container-fluid">
<a class="navbar-brand" href="#"><!--Navbar--></a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarsExampleDefault">
<ul class="navbar-nav me-auto mb-2 mb-md-0">
<li class="nav-item active">
<a class="nav-link" aria-current="page" href="#"><!--Home--></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#"><!--Link--></a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="dropdown01" data-bs-toggle="dropdown" aria-expanded="false"><!--Dropdown--></a>
<ul class="dropdown-menu" aria-labelledby="dropdown01">
<li><a class="dropdown-item" href="#">Action</a></li>
<li><a class="dropdown-item" href="#">Another action</a></li>
<li><a class="dropdown-item" href="#">Something else here</a></li>
</ul>
</li>
</ul>
<!--<form class="d-flex">
<input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success" type="submit">Search</button>
</form>-->
</div>
</div>
</nav>
<main class="container">
<div class="starter-template text-center py-5 px-3">
<p>This animation is driven by real time live data from the <a href="https://www.channelcoast.org/realtimedata/">Channel Coast</a> Porthleven wavebuoy.</p>
<p>The higher the peaks the bigger the swell, the smoother the waves the higher the swel period.</p>
<p><span id="surfheight"></span>m high <br></p>
<p>at <span id="surfperiod"></span> seconds</p>
</div>
<script>
// we make these variables global so we know when they have loaded
let surfheight, surfperiod;
fetch(
"https://data.channelcoast.org/observations/waves/latest?key=6cefd36d8e12a4dead4cf06d4dbd09c0"
)
.then(function (resp) {
return resp.text();
})
.then(function (data) {
//console.log(data);
let parser = new DOMParser(),
xmlDoc = parser.parseFromString(data, "text/xml");
//console.log(xmlDoc.getElementsByTagName('ms:hs')[36].innerHTML); //76=Perran,36 Porthleven
surfheight = xmlDoc.getElementsByTagName("ms:hs")[36].innerHTML;
surfperiod = xmlDoc.getElementsByTagName("ms:tp")[36].innerHTML;
// you can set the surf variable here, because the sketch will start only after the data loads,
// also make sure to first convert it to a number like "Number(surfheight)" otherwise it won't work
surfht = Number(surfheight);
surfpd = Number(surfperiod);
document.getElementById("surfheight").textContent = surfheight;
document.getElementById("surfperiod").textContent = surfperiod;
});
var yoff = 0; // 2nd dimension of perlin noise
var waveColor, waveColor2, waveColor3;
var waveColorArr;
var controls, waveSpeed;
var canvas;
let surfht;
let surfpd;
function setup() {
canvas = createCanvas(windowWidth, windowHeight);
waveColor = color(0, 50, 120, 100);
waveColor2 = color(0, 100, 150, 100);
waveColor3 = color(0, 200, 250, 100);
noiseDetail(2, 0.2);
waveColorArr = [waveColor, waveColor, waveColor2, waveColor2, waveColor3, waveColor3];
}
function draw() {
// after these load, the sketch starts
if (!surfperiod && !surfheight) {
return;
}
background(0);
noStroke();
const amp = map(surfht, 0, 10, 0, 1);
//const amp = map(surfpd, 0, 10, 0, 1);
for (var i = 0; i <= 5; i++) {
// We are going to draw a polygon out of the wave points
beginShape();
fill(waveColorArr[i]);
var xoff = 0;
for (var x = 0; x <= width + 500; x += 100) {
var y = map(
noise(xoff, yoff - 0.5 * i),
0,
1,
(height / 10) * (i + 1),
height - height / 10 + (height / 10) * i
);
vertex(x, y);
// i've extracted this into a variable for cleaner code
const inc = map(surfpd, 0, 20, 0.01, 0.5);
xoff += inc + 0.5 / 10000.0;
}
vertex(width, height);
vertex(0, height);
endShape(CLOSE);
}
const inc = map(surfht, 0, 10, 0, 0.025);
yoff += 0.007 + inc + 0.5 / 10000.0;
}
function windowResized() {
resizeCanvas(window.innerWidth, window.innerHeight);
}
</script>
</main><!-- /.container -->
<script src="../assets/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>