-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
209 lines (185 loc) · 6.44 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
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>y-a-v-a • A Chance of order • 2021</title>
<meta name="description" content="Interpretation of the works of Kenneth Martin in HTML, CSS and JavaScript by Vincent Bruijn - Yet Another Visual Artist">
<meta name="keywords" content="Kenneth Martin, Vincent Bruijn, chance and order, internet art, yet another visual artist">
<meta name="author" content="Vincent Bruijn <vebruijn@gmail.com>">
<link rel="apple-touch-icon-precomposed" sizes="57x57" href="apple-touch-icon-57x57.png" />
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="apple-touch-icon-114x114.png" />
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="apple-touch-icon-72x72.png" />
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="apple-touch-icon-144x144.png" />
<link rel="apple-touch-icon-precomposed" sizes="60x60" href="apple-touch-icon-60x60.png" />
<link rel="apple-touch-icon-precomposed" sizes="120x120" href="apple-touch-icon-120x120.png" />
<link rel="apple-touch-icon-precomposed" sizes="76x76" href="apple-touch-icon-76x76.png" />
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="apple-touch-icon-152x152.png" />
<link rel="icon" type="image/png" href="favicon-196x196.png" sizes="196x196" />
<link rel="icon" type="image/png" href="favicon-96x96.png" sizes="96x96" />
<link rel="icon" type="image/png" href="favicon-32x32.png" sizes="32x32" />
<link rel="icon" type="image/png" href="favicon-16x16.png" sizes="16x16" />
<link rel="icon" type="image/png" href="favicon-128.png" sizes="128x128" />
<meta name="application-name" content="A Chance of order"/>
<style>
:root {
--unit: 1vh;
}
@media (orientation: portrait) {
:root {
--unit: 1vw;
}
}
html {
width: 100%;
height: 100%;
}
body {
background: #F5F0EA;
display: flex;
justify-content: center;
align-items:center;
height: 100%;
width: 100%;
margin: 0;
}
#container {
width: calc(60 * var(--unit));
height: calc(60 * var(--unit));
margin: 0 auto;
position: relative;
}
.line {
position: absolute;
height: var(--unit);
transform-origin: top left;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
(function() {
const transparent = '#FFFFFF00';
// colors taken from Kenneth Martin's work
const backgroundColors = [
'#5AB0C6',
'#F6A752',
'#FE4648',
'#5D63B4'
];
/**
* Create linear gradient CSS programmatically
*/
function generateBackground(amount) {
const stops = [];
for (let i = 1; i <= amount + 1; i++) {
const randomIndex = Math.floor(Math.random() * backgroundColors.length);
const randomColor = backgroundColors[randomIndex];
stops.push(`${transparent} calc(${i - 1} * var(--unit))`);
stops.push(`${transparent} calc(${i - .5} * var(--unit))`);
stops.push(`${randomColor} calc(${i - .5} * var(--unit))`);
stops.push(`${randomColor} calc(${i } * var(--unit))`);
}
return `background: linear-gradient(0deg, ${stops.join(',')});`
}
/**
* Calculate corner in degrees via tangens
*/
function calcAngleDegrees(x, y) {
return Math.atan2(y, x) * -180 / Math.PI;
}
// cache for already used points
const used = [];
// initial coordinates of the square
const points = [
[0,0],
[1,0],
[2,0],
[3,0],
[4,0],
[5,0],
[6,0],
[6,-1],
[6,-2],
[6,-3],
[6,-4],
[6,-5],
[6,-6],
[5,-6],
[4,-6],
[3,-6],
[2,-6],
[1,-6],
[0,-6],
[0,-5],
[0,-4],
[0,-3],
[0,-2],
[0,-1],
];
// generate 12 bars
for (let i = 0; i < 12; i++) {
const indexSet = new Set();
// create a set of 2 unique coordinates
while (indexSet.size < 2) {
const val = Math.floor(Math.random() * 24);
if (used.indexOf(val) === -1) {
indexSet.add(val);
used.push(val);
}
}
const indexes = [...indexSet];
const index1 = indexes[0];
const index2 = indexes[1];
// sort to get lowest x first
const localPoints = [points[index1], points[index2]].sort((a,b) => a[0] > b[0] ? 1 : a[0] < b[0] ? -1 : 0);
const point1 = localPoints[0];
const point2 = localPoints[1];
// define x position for css
const left = point1[0] * 10;
const top = Math.abs(point1[1] * 10);
// calculate deltas
const deltaX = point2[0] - point1[0];
const deltaY = point2[1] - point1[1];
// calculate corner in degrees
const deg = calcAngleDegrees(deltaX, deltaY);
// calculate hypotenuse, i.e. the width of the element
const sin = Math.sin(Math.atan2(deltaY, deltaX));
const width = (sin ? Math.abs(deltaY / sin) : deltaX) * 10;
// calculate height based on index
const height = i + 1 * 1;
// move rectangles a bit more within the container
let translateY = 0;
if (sin === 0 && point1[1] < -5) {
translateY = -height;
} else if (sin === 1 && point1[0] > 5) {
translateY = -height;
} else if (sin < -.5 && point1[0] === 0) {
translateY = -height;
} else if (sin > .5 && sin < 1) {
translateY = -height;
}
// generate CSS
const css = [
`left: calc(${left} * var(--unit));`,
`top: calc(${top} * var(--unit));`,
`transform: rotate(${deg}deg) translateY(calc(${translateY} * var(--unit)));`,
`width: calc(${width} * var(--unit));`,
`height: calc(${height} * var(--unit));`,
`${generateBackground(i)}`
].join('');
// create bar
const el = document.createElement('div');
el.classList.add('line');
el.classList.add(`line-${i}`);
el.setAttribute('style', css);
// add bar to container
const canvas = document.getElementById('container');
canvas.appendChild(el);
}
}());
</script>
</body>
</html>