-
Notifications
You must be signed in to change notification settings - Fork 0
/
setupInteractions.js
executable file
·275 lines (218 loc) · 6.59 KB
/
setupInteractions.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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
"use strict";
// make the input image object, set initial interpolation method
var inputImage=new InputImage();
inputImage.periodic=inputImagePeriodic;
var interpolation="nearest";
inputImage.interpolation=inputImage.getNearest;
// setting up the buttons
// the input image
// get the input image pixels, adjust the reference, set the inputTransform
var imageInputButton = new Button('imageInput');
imageInputButton.onChange(function(){
inputImage.read(imageInputButton.button.files[0],function(){
// referenceCanvas.adjust();
//referenceCanvas.adjustToOutput();
inputTransform.setShift(0.5*inputImage.width,0.5*inputImage.height);
//inputTransform.setScale(initialInputScale);
createImage();
});
});
// choosing the output width
var outputWidthChooser=new Button('outputWidthChooser');
//var outputHeightChooser=new Button('outputHeightChooser');
/*
// the reference image height
var referenceHeightChooser=new Button('referenceHeightChooser');
referenceHeightChooser.setValue(referenceCanvasHeight);
*/
// set the start values
outputWidthChooser.setValue(initialOutputWidth);
//outputHeightChooser.setValue(initialOutputHeight);
var backgroundRedChooser=new Button('backgroundRed');
backgroundRedChooser.setValue(backgroundRed);
var backgroundGreenChooser=new Button('backgroundGreen');
backgroundGreenChooser.setValue(backgroundGreen);
var backgroundBlueChooser=new Button('backgroundBlue');
backgroundBlueChooser.setValue(backgroundBlue);
// the smoothing variants
var smoothing=false;
var smoothingText="No"
var smoothingChoosers=new Chooser('smoothing');
smoothingChoosers.add(function(){
smoothing=false;
smoothingText="No";
console.log("smoothing "+smoothing);
});
smoothingChoosers.add(function(){
smoothing=true;
smoothingText="2x2",
console.log("smoothing "+smoothing);
});
smoothingChoosers.setCheckedFirst();
// the interpolation method
var interpolationChoosers=new Chooser('interpolation');
interpolationChoosers.add(function(){
inputImage.interpolation=inputImage.getNearest;
interpolation="nearest";
});
interpolationChoosers.add(function(){
inputImage.interpolation=inputImage.getLinear;
interpolation="linear";
});
interpolationChoosers.add(function(){
inputImage.interpolation=inputImage.getCubic;
interpolation="cubic";
});
interpolationChoosers.setCheckedFirst();
// do the changes
var updateButton=new Button("update");
updateButton.onClick(function(){
createImage();
});
// do the changes
var exploreButton=new Button("explore");
exploreButton.onClick(function(){
outputWidthChooser.setValue(500);
smoothing=false;
smoothingText="no",
inputImage.interpolation=inputImage.getNearest;
interpolation="nearest";
console.log("explore");
createImage();
});
// do the changes
var posterButton=new Button("poster");
posterButton.onClick(function(){
outputWidthChooser.setValue(7100);
smoothing=true;
smoothingText="2x2",
inputImage.interpolation=inputImage.getCubic;
interpolation="cubic";
console.log("poster");
createImage();
});
// the color modification (inversion)
var nColorMod=0;
var colorMod="none";
var inversionChoosers=new Chooser('inversion');
inversionChoosers.add(function(){
nColorMod = 0;
colorMod="none";
createImage();
});
inversionChoosers.add(function(){
nColorMod = 1;
colorMod="first";
createImage();
});
inversionChoosers.add(function(){
nColorMod = 2;
colorMod="second";
createImage();
});
inversionChoosers.setCheckedFirst();
// the harmonics
var harmonicsChooser=new Button("harmonics");
harmonicsChooser.setValue(initialHarmonics);
harmonicsChooser.onChange(function(){
var n=harmonicsChooser.getValue();
if (n<=0){
imageFastFunction.makeTriangleTable();
}
else {
imageFastFunction.makeTriangleExpansionTable(n);
}
map.isValid=false;
createImage();
})
// imageCombination
var combinationChooser=new Chooser('combination');
combinationChooser.add(function(){
imageCombination=makeSum;
map.isValid=false;
createImage();
});
combinationChooser.add(function(){
imageCombination=makeProduct;
map.isValid=false;
createImage();
});
combinationChooser.add(function(){
imageCombination=makeMax;
map.isValid=false;
createImage();
});
combinationChooser.add(function(){
imageCombination=makeMin;
map.isValid=false;
createImage();
console.log("min");
});
combinationChooser.add(function(){
imageCombination=makeAbsoluteMinimum;
map.isValid=false;
createImage();
});
combinationChooser.add(function(){
imageCombination=makeAbsoluteSum;
map.isValid=false;
createImage();
});
combinationChooser.setCheckedFirst();
// rosette for poincare disc etc.
var rosetteChooser=new Chooser('rosette');
rosetteChooser.add(function(){
basicRosette=rosettePeriodicMirrorPhi;
map.isValid=false;
createImage();
})
rosetteChooser.add(function(){
basicRosette=rosetteRotationMirror;
map.isValid=false;
createImage();
})
rosetteChooser.add(function(){
basicRosette=rosetteRotation;
map.isValid=false;
createImage();
})
rosetteChooser.setCheckedFirst();
// the message
var progress=document.getElementById("progress");
progress.innerHTML="Waiting for input image.";
// the message
var averageColor=document.getElementById("averageColor");
averageColor.innerHTML="Average color.";
function progressMessage(){
progress.innerHTML="Size "+outputWidthChooser.getValue()+
". "+smoothingText+" smoothing. Interpolation "+interpolation+". Color modification "+colorMod+".";
}
var averageAsBackground=null;
function colorMessage(red,green,blue){
averageColor.innerHTML="average color: red "+red+", green "+green+", blue "+blue+".";
averageColor.innerHTML+="<button type='button' id='asBackground'>as background</button>";
averageAsBackground=new Button("asBackground");
averageAsBackground.onClick(function(){
backgroundRedChooser.setValue(averageRed);
backgroundGreenChooser.setValue(averageGreen);
backgroundBlueChooser.setValue(averageBlue);
createImage();
});
}
var saveOutputImageJpgButton=new Button("downloadOutputJpg");
saveOutputImageJpgButton.onClick(function(){
outputCanvas.saveImageJpg("outputImage");
});
/*
var saveOutputImagePngButton=new Button("downloadOutputPng");
saveOutputImagePngButton.onClick(function(){
outputCanvas.saveImagePng("outputImage");
referenceCanvas.saveImagePng("referenceImage");
});
*/
/*
var saveReferenceImagePngButton=new Button("downloadReferencePng");
saveReferenceImagePngButton.onClick(function(){
referenceCanvas.saveImagePng("referenceImage");
});
*/