-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsketch.js
34 lines (31 loc) · 808 Bytes
/
sketch.js
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
var allfriends = {};
var radius = 200;
function setup() {
createCanvas(960, 547);
loadJSON("data.json", setupFriends);
};
function draw() {
background(0);
for (var f in allfriends) {
allfriends[f].render();
}
};
function setupFriends(data) {
var friends = data.friends.data;
for (var i=0; i<friends.length; i++) {
var name = friends[i].name;
var id = friends[i].id;
var mutualfriends = [];
if (friends[i].hasOwnProperty("mutualfriends")) {
mutualfriends = friends[i].mutualfriends.data;
}
var theta = map(i, 0, friends.length, 0, TWO_PI);
var x = width / 2 + cos(theta) * radius;
var y = height / 2 + sin(theta) * radius;
var f = new Friend(name, id, mutualfriends, x, y, theta);
allfriends[id] = f;
}
for (var k in allfriends) {
allfriends[k].connectToFriends();
}
};