-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwaves_function.js
More file actions
86 lines (70 loc) · 3.27 KB
/
waves_function.js
File metadata and controls
86 lines (70 loc) · 3.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
function drawWaves(now) {
if (!layers.waves || !waveData.length) return;
waveData.forEach(wave => {
const dist = d3.geoDistance([wave.lon, wave.lat], projection.rotate().map(d => -d));
if (dist > Math.PI / 2) return;
const center = projection([wave.lon, wave.lat]);
if (!center) return;
const baseRadius = 3;
const maxRadius = 15;
const radius = baseRadius + (wave.height / 10) * (maxRadius - baseRadius);
const intensity = Math.min(wave.height / 10, 1);
const blue = Math.floor(100 + intensity * 155);
const color = `rgba(0, ${Math.floor(blue * 0.6)}, ${blue}, 0.6)`;
const pulsePhase = (now / 2000) % 1;
ctx.save();
for (let i = 0; i < 3; i++) {
const phaseOffset = i * 0.33;
const currentPhase = (pulsePhase + phaseOffset) % 1;
const currentRadius = radius * (0.5 + currentPhase * 0.5);
const alpha = 0.6 * (1 - currentPhase);
ctx.beginPath();
ctx.arc(center[0], center[1], currentRadius, 0, Math.PI * 2);
ctx.strokeStyle = color.replace(/[\d.]+\)$/, `${alpha})`);
ctx.lineWidth = 2;
ctx.stroke();
}
ctx.beginPath();
ctx.arc(center[0], center[1], 2, 0, Math.PI * 2);
ctx.fillStyle = color;
ctx.fill();
if (wave.direction) {
const dirRad = (wave.direction - 90) * Math.PI / 180;
const arrowLen = radius * 0.6;
ctx.beginPath();
ctx.moveTo(center[0], center[1]);
ctx.lineTo(
center[0] + Math.cos(dirRad) * arrowLen,
center[1] + Math.sin(dirRad) * arrowLen
);
ctx.strokeStyle = color.replace(/[\d.]+\)$/, '0.4)');
ctx.lineWidth = 1;
ctx.stroke();
const headSize = 3;
const headAngle = 30 * Math.PI / 180;
const tipX = center[0] + Math.cos(dirRad) * arrowLen;
const tipY = center[1] + Math.sin(dirRad) * arrowLen;
ctx.beginPath();
ctx.moveTo(tipX, tipY);
ctx.lineTo(
tipX - Math.cos(dirRad - headAngle) * headSize,
tipY - Math.sin(dirRad - headAngle) * headSize
);
ctx.moveTo(tipX, tipY);
ctx.lineTo(
tipX - Math.cos(dirRad + headAngle) * headSize,
tipY - Math.sin(dirRad + headAngle) * headSize
);
ctx.stroke();
}
ctx.restore();
hoverTargets.push({
id: `wave-${wave.name}`,
type: 'wave',
x: center[0],
y: center[1],
radius: radius,
data: wave
});
});
}