-
Notifications
You must be signed in to change notification settings - Fork 3
/
generator.js
212 lines (169 loc) · 6.01 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
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
let fingers;
let handColors = [
'#FFAA00',
'#FF00AA',
'#AA00FF',
'#00AAFF'
];
let boxColor = '#AAFF00';
let tinyFingers = true;
let sizex = 420;
let sizey = 420;
let imgcount = 0;
let recording = false;
paper.install(window);
window.onload = async function() {
paper.setup('myCanvas');
let canvas = document.getElementById('myCanvas');
const recorder = new CanvasRecorder(canvas, 4500000);
var downloadLink = document.createElement("a");
document.body.appendChild(downloadLink);
shuffle();
generate();
//genGrid();
//genStickers();
if(recording){
recorder.start();
}
//genAnimation();
if(recording){
view.onClick = function(){
recorder.stop();
recorder.save('finger_motion.webm');
}
}
}
function genAnimation(){
fingers = new Finger([sizex, sizey], view.bounds.center.add([-900,-400]), handColors.concat([boxColor]), false, 'animation');
let fingers1 = new Finger([sizex, sizey], view.bounds.center.add([-900,400]), handColors.concat([boxColor]), false, 'animation');
let fingers2 = new Finger([sizex, sizey], view.bounds.center.add([0,-400]), handColors.concat([boxColor]), false, 'animation');
let fingers3 = new Finger([sizex, sizey], view.bounds.center.add([0,400]), handColors.concat([boxColor]), false, 'animation');
let fingers4 = new Finger([sizex, sizey], view.bounds.center.add([900,-400]), handColors.concat([boxColor]), false, 'animation');
let fingers5 = new Finger([sizex, sizey], view.bounds.center.add([900,400]), handColors.concat([boxColor]), false, 'animation');
//fingers = new Finger([sizex, sizey], view.bounds.center, handColors.concat([boxColor]), false, 'animation');
}
function genStickers(){
fingers = new Finger([sizex, sizey], view.bounds.center, handColors.concat([boxColor]), false, 'sticker');
}
function genGrid(){
let s = 350;
let d = 150;
fingers = new Finger([s*2+d, s*2+d], [300+s+d/2, 300+s+d/2], handColors.concat([boxColor]), false);
let oldColors = [boxColor].concat(handColors);
let colors = _.shuffle(oldColors);
boxColor = colors.pop();
handColors = colors;
fingers = new Finger([s, s*3+d*2], [300+s*2.5+d*2, 300+s*1.5+d], handColors.concat([boxColor]), false);
oldColors = [boxColor].concat(handColors);
//colors = _.shuffle(oldColors);
boxColor = colors.pop();
handColors = colors;
fingers = new Finger([s, s], [300+s*0.5, 300+s*2.5+d*2], handColors.concat([boxColor]), false);
oldColors = [boxColor].concat(handColors);
//colors = _.shuffle(oldColors);
boxColor = colors.pop();
handColors = colors;
fingers = new Finger([s, s], [300+s*1.5+d, 300+s*2.5+d*2], handColors.concat([boxColor]), false);
}
function generate(text){
project.activeLayer.removeChildren();
let val = document.getElementById("textinput").value
fingers = new Finger([sizex, sizey], view.bounds.center, handColors.concat([boxColor]), false, 'none', val);
if(!tinyFingers){
fingers.removeTinyFingers();
}
}
function shuffle(){
let oldColors = handColors.concat([boxColor]);
let colors = _.shuffle(oldColors);
boxC = colors.pop();
handC = colors;
if(fingers){
changeColor('boxcolor', Color.random());
changeColor('fillcolor1', Color.random());
changeColor('fillcolor2', Color.random());
changeColor('fillcolor3', Color.random());
changeColor('fillcolor4', Color.random());
changeColor('boxcolor', boxC);
changeColor('fillcolor1', handC[0]);
changeColor('fillcolor2', handC[1]);
changeColor('fillcolor3', handC[2]);
changeColor('fillcolor4', handC[3]);
}
handColors = handC;
boxColor = boxC;
document.getElementById('boxcolor').value = boxColor;
document.getElementById('fillcolor1').value = handColors[0];
document.getElementById('fillcolor2').value = handColors[1];
document.getElementById('fillcolor3').value = handColors[2];
document.getElementById('fillcolor4').value = handColors[3];
}
function toggleFingers(){
if(tinyFingers){
fingers.removeTinyFingers();
}else{
fingers.insertTinyFingers();
}
tinyFingers = !tinyFingers;
}
var changeText = _.debounce(function (text) {
generate(text);
}, 500);
function changeSize(name, value){
if(name == 'sizex'){
sizex = value;
}
if(name == 'sizey'){
sizey = value;
}
}
function changeStyle(val){
if(val == 'fill'){
fingers.makeColored();
}
if(val == 'nofill'){
fingers.makeLineArt();
}
}
function changeColor(colorname, value){
if(colorname == 'fillcolor1'){
fingers.changeColor(handColors[0], value);
handColors[0] = value;
}
if(colorname == 'fillcolor2'){
fingers.changeColor(handColors[1], value);
handColors[1] = value;
}
if(colorname == 'fillcolor3'){
fingers.changeColor(handColors[2], value);
handColors[2] = value;
}
if(colorname == 'fillcolor4'){
fingers.changeColor(handColors[3], value);
handColors[3] = value;
}
if(colorname == 'boxcolor'){
fingers.changeColor(boxColor, value);
boxColor = value;
}
}
function downloadSVG(){
var svg = project.exportSVG({ asString: true });
var svgBlob = new Blob([svg], {type:"image/svg+xml;charset=utf-8"});
var svgUrl = URL.createObjectURL(svgBlob);
var downloadLink = document.createElement("a");
downloadLink.href = svgUrl;
downloadLink.download = "funkyfingers.svg";
document.body.appendChild(downloadLink);
downloadLink.click();
document.body.removeChild(downloadLink);
}
function downloadPNG(){
var canvas = document.getElementById("myCanvas");
var downloadLink = document.createElement("a");
downloadLink.href = canvas.toDataURL("image/png;base64");
downloadLink.download = 'funkyfingers.png'
document.body.appendChild(downloadLink);
downloadLink.click();
document.body.removeChild(downloadLink);
}