-
Notifications
You must be signed in to change notification settings - Fork 1
/
weird-triangles.html
58 lines (54 loc) · 1.7 KB
/
weird-triangles.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
<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.14/p5.js"></script>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
</head>
<body>
<script>
// p5 script adapted from
// https://generativeartistry.com/tutorials/triangular-mesh/
var palette = ["#152A84", "#776EAA", "#201315", "#DB1D6B", "#CDE4CF", "#008460", "#DBE479", "#F1C42F", "#E22733", "#FFFFFF"];
var w = 800;
var h = 800;
function setup(){
createCanvas(w, h);
background("#008460");
colorMode(HSB,360,100,100)
noFill();
gap = 80;
odd = false;
lines = [];
stroke("#F1C42F");
strokeWeight(2);
for(var y = gap / 2; y <= h; y+= gap) {
odd=!odd;
lineA = [];
for (var x = gap / 4; x <= w; x+= gap) {
if (odd) {t = x + (gap / 2);} else {t=x;}
dot={t,y};if(odd){stroke(230,100,100);}else{stroke(30,100,100);}ellipse(t,y,7,7)
lineA.push({
t: x + (Math.random()*.4 - .4) * gap + (odd ? gap/2 : 0),
y: y + (Math.random()*.4 - .4) * gap
});
}
lines.push(lineA)
}
var dotLine;
odd = true;
for(var y = 0; y < lines.length - 1; y++) {
odd = !odd;
dotLine = [];
for(var i = 0; i < lines[y].length; i++) {
dotLine.push(odd ? lines[y][i] : lines[y+1][i]);
dotLine.push(odd ? lines[y+1][i] : lines[y][i]);
}
for(var i = 0; i < dotLine.length - 2; i++) {
triangle(dotLine[i].t, dotLine[i].y, dotLine[i+1].t, dotLine[i+1].y, dotLine[i+2].t, dotLine[i+2].y);
}
}
}
</script>
</body>
</html>