-
Notifications
You must be signed in to change notification settings - Fork 0
/
generator.js
131 lines (113 loc) · 4.04 KB
/
generator.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
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
/*global Chance, chance, Snap, console, alert, window, location,*/
/*jslint plusplus: true*/
var centerH = window.innerWidth / 2,
centerV = window.innerHeight / 2,
boundSize = window.innerWidth / 3,
quarterSize = boundSize / 4,
xStart = centerH - (boundSize / 2),
yStart = centerV - (boundSize / 2),
//seededChance is only used to generate the hashes, then those values are used for URLs and Colors, sizes, etc.
seededChance = new Chance(chance.hash({length: 3})),
hashes = [],
h,
latest,
s;
//COLORS
var palette = [["422ef4", "ff84a8", "ffdd8e", "ffffff"], //load these from a txt file?
["000000", "ff6050", "95e2e7", "fff8d3"],
["1b1e9b", "c342a3", "44c0ff", "f6d579"],
["1e2e62", "f9517e", "44c0ff", "dce8eb"],
["3a1464", "ef3c25", "fbb03b", "ffffff"],
["1b1e9b", "e1116a", "ffcd06", "75d9f8"],
["921e51", "c93559", "66d3a9", "fff8d3"],
["cc3e3e", "ff6050", "75d9f8", "ffffff"],
["094bd1", "ffcd06", "93e3da", "fff5c5"],
["000000", "147dff", "cccccc", "ffffff"],
["000000", "fa2cc4", "02feff", "ffffff"],
["000000", "147dff", "ffff02", "ffffff"],
["c64f4f", "7594ff", "eadcb9", "c2fff6"],
["000000", "4d4d4d", "cccccc", "ffffff"],
["000000", "ff6050", "cccccc", "ffffff"],
["000000", "ff6050", "cccccc", "ffffff"],
["000000", "fa2cc4", "cccccc", "ffffff"],
["000000", "e1116a", "147dff", "ffffff"]];
function genArt(g) {
"use strict";
console.log("genArt " + g);
//new snap viewbox
var s = new Snap("#svg").attr({
viewBox: "0 0 " + window.innerWidth + " " + window.innerHeight,
width: "100%",
height: "100%"
}),
bg = s.circle(centerH, centerV, 5000, 5000), //big ass circle as a background for now (find a better bg solution???)
gen = new Chance(g),
shade = gen.integer({min: 0, max: 15}),
x = 0,
y = 0;
var nodes = [
[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12],
[13, 14, 15, 16]
];
for (x = 0; x < nodes.length; x++) {
var node = nodes[x];
for (y = 0; y < node.length; y++) {
node[y] = s.rect(xStart + (quarterSize * x), yStart + (quarterSize * y), quarterSize, quarterSize);
node[y].attr({fill: "#" + palette[shade][gen.integer({min: 0, max: 3})]});
}
}
bg.attr({fill: "#" + palette[shade][3] }); //creates a background color thats always the lightest shade
}
function generateHash() {
"use strict";
location.hash = seededChance.hash({length: 3});
console.log("new hash generated: " + location.hash);
h = location.hash;
hashes.push(h);
genArt(location.hash);
}
//generates art based on the previous hash
function sameHash() {
"use strict";
//var seededChance = new Chance(chance.hash({length: 3}));
var sHash = window.location.hash.substring(window.location.hash.lastIndexOf('#') + 1);
//console.log("same hash being used: " + hashes[hashes.length - 1]);
//latest = hashes[hashes.length - 1];
genArt(sHash);
}
window.onload = function () {
"use strict";
console.log("onLoad");
if (window.location.hash.substring(window.location.hash.lastIndexOf('/') + 1).length === 0) {
generateHash();
} else {
console.log("Linked to pre-hashed page " + location.hash);
genArt(location.hash);
}
};
window.onkeyup = function (e) {
"use strict";
switch (e.keyCode) {
case 37: //left
console.log("onkeyup");
generateHash();
break;
case 38: //up
console.log("onkeyup");
generateHash();
break;
case 39: //right
console.log("onkeyup");
generateHash();
break;
case 40: //down
console.log("onkeyup");
generateHash();
break;
case 32: //space
console.log(hashes);
break;
}
};