-
Notifications
You must be signed in to change notification settings - Fork 0
/
vvv-logo.html
218 lines (198 loc) · 6.84 KB
/
vvv-logo.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
210
211
212
213
214
215
216
217
218
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>VVV</title>
<script type="text/javascript" src="paper.js"></script>
<script src="jquery-1.10.2.min.js"></script>
<script type="text/paperscript" canvas="stage">
window.vvv = (function() {
var stage = $('#stage'),
defaults = {
triangleOffset: 3.5,
radius: 150,
rotationSpeed: 0.8,
strokeWidthRatio: 0.05,
showIntersections: false,
centre: null,
offset_x: null,
offset_y: null,
chaos: {
opacityMin: 0.8,
opacityMax: 1,
strokeMin: 0,
strokeMax: 1,
colorise: false,
},
triangles: {
opacity: 0.8,
strokeColor: '#fff',
strokeJoin: 'miter',
strokeWidth: 1
},
circles: {
opacity: 0.3,
strokeColor: '#999',
strokeWidth: 1
}
},
conf = $.extend(true, {}, defaults),
objects = {};
function update() {
// calculate values dependent on radius
conf.offset_x = conf.radius / conf.triangleOffset;
conf.offset_y = Math.round(conf.offset_x * Math.tan(Math.PI/3)); //tan(60)
conf.triangles.strokeWidth = Math.round(conf.radius * conf.strokeWidthRatio);
conf.centre = new Point(stage.width()/2, Math.round(stage.height()/2 - conf.radius/3));
render();
}
function render() {
project.activeLayer.removeChildren();
objects.circles = [];
objects.triangles = [];
$([ conf.centre,
new Point(conf.centre.x - conf.offset_x, conf.centre.y + conf.offset_y),
new Point(conf.centre.x + conf.offset_x, conf.centre.y + conf.offset_y) ]).each(function(i, pt) {
objects.triangles.push(drawTriangle(pt));
objects.circles.push(drawCircle(pt, conf.radius * .99));
});
}
function drawCircle(centre, radius) {
var c = new Path.Circle(centre, radius);
c.set(conf.circles);
c._centre = centre;
return c;
}
function drawTriangle(centre) {
var t = new Path.RegularPolygon(centre, 3, conf.radius);
t.set(conf.triangles);
t.rotate(60, centre);
t._centre = centre;
return t;
}
function rand(min, max) {
return Math.random() * (max - min) + min;
}
// add toggle state
$('#controls button').click(function() {
$(this).data('state', ($(this).data('state')) ? 0 : 1);
});
$('#btn-rotation').click(function() {
conf.rotationSpeed = ($(this).data('state')) ? 0 : defaults.rotationSpeed;
});
$('#btn-circles').click(function() {
conf.circles.opacity = ($(this).data('state')) ? 0 : defaults.circles.opacity;
});
$('#btn-triangles').click(function() {
if ($(this).data('state')) {
conf.triangles.opacity = 0;
conf.showIntersections = true;
} else {
conf.triangles.opacity = defaults.triangles.opacity;
conf.showIntersections = false;
}
});
$('#btn-colorise').click(function() {
conf.chaos.colorise = !conf.chaos.colorise;
console.log(conf.chaos.colorise);
});
$('#btn-chaos').click(function() {
if ($(this).data('state')) {
conf.chaos = $.extend(conf.chaos, {
colorise: true,
strokeMax: Math.round(conf.triangles.strokeWidth * 1.5),
strokeMin: Math.round(conf.triangles.strokeWidth * -0.1)
});
} else {
conf.chaos = $.extend({}, defaults.chaos);
console.log(conf.chaos);
}
});
update();
return {
'config': conf,
'objects': objects,
'update': update,
'rand': rand
};
}());
var intersectionGroup = new Group();
function onFrame(event) {
var cfg = vvv.config,
ts = vvv.objects.triangles,
cs = vvv.objects.circles,
intersections, j, intersectionPath;
intersectionGroup.removeChildren();
$(ts).each(function(i, t) {
// create chaos
t.strokeWidth = cfg.triangles.strokeWidth + Math.floor(vvv.rand(cfg.chaos.strokeMin, cfg.chaos.strokeMax));
t.opacity = cfg.triangles.opacity * vvv.rand(cfg.chaos.opacityMin, cfg.chaos.opacityMax);
if (cfg.chaos.colorise === true) {
t.strokeColor.hue += i+1;
t.strokeColor.lightness = 0.5;
t.strokeColor.saturation = 1;
} else {
t.strokeColor = cfg.triangles.strokeColor;
}
// update circle opacity
cs[i].opacity = cfg.circles.opacity;
// rotate
t.rotate(cfg.rotationSpeed, t._centre);
// draw intersections
if (cfg.showIntersections === true) {
intersections = ts[i].getIntersections(cs[i]);
for (j = 0; j < intersections.length; j++) {
intersectionPath = new Path.Circle({
center: intersections[j].point,
radius: 4,
fillColor: '#df1333'
});
intersectionGroup.addChild(intersectionPath);
}
}
});
}
</script>
<style type="text/css">
body {
background: #000;
color: #fff;
margin: 0;
padding: 0;
font: normal 12px monospace;
text-align: center;
}
#controls {
position: fixed;
z-index: 2;
top: 0;
left: 0;
}
#controls button {
background: 0;
font: normal 12px monospace;
color: #fff;
border: 0;
cursor: pointer;
text-decoration: underline;
}
canvas {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
}
</style>
</head>
<body>
<div id="controls">
<button id="btn-rotation">toggle rotation</button>
<button id="btn-circles">toggle circles</button>
<button id="btn-triangles">toggle triangles/dots</button>
<button id="btn-colorise">toggle colors</button>
<button id="btn-chaos">toggle chaos</button>
</div>
<canvas id="stage" resize></canvas>
</body>
</html>