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
export default async function (req: Request): Promise<Response> {
const html = `<!DOCTYPE html>
<html>
<head>
<title>Mouse-Following Triangle Pattern</title>
<!-- Load the Processing.js library -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/processing.js/1.6.0/processing.min.js"></script>
</head>
<body>
<script type="application/processing">
float s = 4;
float w = 400;
// Function to calculate the vertex positions
float[] a(float x, float y) {
float k = mouseX - x;
float e = mouseY - y;
float d = -exp(-mag(k, e) / (40 + 145 * noise(x / 50, y / 50)));
return new float[]{x + k * d, y + e * d};
}
void setup() {
size(400, 400);
noFill();
}
void draw() {
background(248);
for (float y = 0; y < w; y += s) {
for (float x = 0; x < w; x += s) {
float[] p1 = a(x, y);
float[] p2 = a(x, y + s);
float[] p3 = a(x + s, y);
triangle(p1[0], p1[1], p2[0], p2[1], p3[0], p3[1]);
}
}
}
</script>
<canvas> </canvas>
</body>
</html>
`;
return new Response(html, {
headers: {
'Content-Type': 'text/html',
},
});
}