-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
133 lines (107 loc) · 3.51 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Calm Breath</title>
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<style>
body {
margin: 0;
padding: 0;
background-color: #B9CBD9;
}
#canvas {
position: absolute;
width: 100%;
height: 100%;
overflow: hidden
}
</style>
<script type="text/javascript">
function showAxes(ctx, axes) {
var width = ctx.canvas.width;
var height = ctx.canvas.height;
var xMin = 0;
ctx.beginPath();
ctx.strokeStyle = "rgb(215, 226, 232)";
// X-Axis
// ctx.moveTo(xMin, height / 2);
// ctx.lineTo(width, height / 2);
// Y-Axis
ctx.moveTo(width / 2, yBuffer);
ctx.lineTo(width / 2, height - yBuffer);
// Starting line
// ctx.moveTo(0, 0);
// ctx.lineTo(0, height);
ctx.stroke();
}
function drawPoint(ctx, y) {
var radius = 18;
ctx.beginPath();
// Hold x constant at 4 so the point only moves up and down.
ctx.arc(ctx.canvas.width / 2, y, radius, 0, 2 * Math.PI, false);
ctx.fillStyle = 'rgb(252, 201, 197)';
ctx.fill();
ctx.lineWidth = 1;
ctx.strokeStyle = 'rgb(252, 201, 197)';
ctx.stroke();
}
function plotSine(ctx, xOffset, yOffset) {
var width = ctx.canvas.width;
var height = ctx.canvas.height;
ctx.beginPath();
ctx.lineWidth = 5;
ctx.strokeStyle = "rgb(252, 201, 197)";
var dotY = 0;
var firstY = 0;
var x = 0;
var y = 0;
var amplitude = 80;
var frequency = 420;
ctx.moveTo(x, yOffset);
while (x < width) {
var sine = Math.sin((x + xOffset / 4.2) / frequency);
y = height / 2 + (height / 2 - yBuffer) * sine;
ctx.lineTo(x, y);
if (x == 4) {
firstY = y;
}
if (x == Math.round(width / 2)) {
dotY = y;
}
x++;
lastY = 0;
}
ctx.stroke();
ctx.save();
drawPoint(ctx, dotY);
ctx.stroke();
ctx.restore();
return firstY;
}
function draw(timestamp) {
var canvas = document.getElementById("canvas");
canvas.width = document.documentElement.clientWidth;
canvas.height = document.documentElement.clientHeight;
var context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
showAxes(context);
context.save();
y = plotSine(context, timestamp, y);
context.restore();
window.requestAnimationFrame(draw);
}
function init() {
window.requestAnimationFrame(draw);
}
var y = 50;
// Y axis buffer for spacing
var yBuffer = 20;
</script>
</head>
<body onload="init()">
<canvas id="canvas"></canvas>
<script src="https://tinylytics.app/embed/QLgVSNQyaejsk3yKeZyn.js" defer></script>
</body>
</html>