-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUndertones2.pde
404 lines (341 loc) · 11 KB
/
Undertones2.pde
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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
PImage img;
var value,
allCharz,
allCharzKeyed,
allCharzLength,
typingCount,
filenameSave,
timearray, timename,
now, hour1, minute1, second1, month1, day1, year1;
String poetry = "The \"smell\" of smoke like a cane and fur coat on the neck of those who come and go. Why, is it, that we don't know?";
String howl1 = "I saw the best minds of my generation destroyed by madness";
String howl2 = "I’m with you in Rockland in my dreams you walk dripping from a sea-journey on the highway across America in tears to the door of my cottage in the Western night.";
String howl3 = "What sphinx of cement and aluminum bashed open their skulls and ate up their brains and imagination?";
String typedString;
String[] chars;
int dataAmount;
int dataRepeat;
int randomCount;
int limitFade;
int[] clr = new int[3];
int[] clrTarget = new int[3];
color c1;
PixelBox[] pixbox = new PixelBox[0];
//Set up ASCII CHAR arrays for comparison with text
String[] csv_input;
float[] asciiDEC;
String[] asciiCHAR;
float[] conversionValuesArray;
float[] conversionColorsArray;
String[] reformedChars;
String reformedText;
String codeKey;
String[] codeKeySplit;
String[] parseRT;
int xCount = 0;
int yCount = 0;
int colorCount = 0;
int pixelSize = 1;
int colorBoxSize = 10;
int recordMode = 0;
float lastMillis = 0;
float mm;
boolean textEntered;
boolean makePixel;
color thisBlock;
String imageName = "1234.png";
void setup() {
size(320, 400);
smooth();
background(255);
noStroke();
img = loadImage(imageName);
//chars = poetry.split("");
//println(chars);
csv_input = loadStrings("ASCII_DEC_values.csv");
asciiDEC = new float[csv_input.length];
asciiCHAR = new String[csv_input.length];
chars = new String[csv_input.length];
conversionValuesArray = new float[0];
conversionColorsArray = new float[0];
reformedChars = new String[0];
loadASCII(); //function to load ascii from csv
//set codeKey
codeKey = "1234";
codeKeySplit = codeKey.split("");
console.log("codeKeySplit = "+codeKeySplit);
dataAmount = ((width/colorBoxSize)*(height/colorBoxSize))*3;
limitFade = floor(random(50, 200));
clrTarget[0] = floor(random(100, 220));
clrTarget[1] = floor(random(100, 220));
clrTarget[2] = floor(random(100, 220));
}
void draw() {
if(makePixel == true){
colorGrid();
}
for (int i = 0; i < pixbox.length; i++) {
pixbox[i].display();
pixbox[i].update();
}
}
void loadASCII(){
//load ASCII DEC values and CHAR values from CSV
for (int i = 0; i < csv_input.length; i++) {
String[] splits = csv_input[i].split(",");
asciiDEC[i] = float(splits[0]);
asciiCHAR[i] = splits[1];
asciiCHAR[12] = ",";
asciiCHAR[2] = "\"";
}
}
void parseText(String[] chars){
chars = allCharz;
dataRepeat = dataAmount/chars.length;
matchCharacters(chars);
}
void matchCharacters(String[] chars){
//clear conversionColorsArray if this is not the first translateColor
conversionValuesArray = new float[0];
for(int x=0; x < dataRepeat; x++){
for(int i = 0; i < chars.length; i++){
for(int j = 0; j < csv_input.length; j++){
if(chars[i].equals(asciiCHAR[j])){
int matchVals = int(asciiDEC[j]);
//println("matchVals = "+matchVals);
conversionValuesArray = append(conversionValuesArray, matchVals);
//println("conversionValuesArray"+i+ " = " +conversionValuesArray[i]);
}
}
}
}
colorCount = 0;
yCount=0;
xCount=0;
makePixel = true;
pixbox = expand(pixbox, 0);
console.log("conversionValuesArray.length = " + conversionValuesArray.length);
}
void colorGrid(){
//make the color grid
if(colorCount < dataAmount){
//if (millis() > lastMillis+0) { //been at least 1 millis
//lastMillis=millis();
if (xCount < width) {
for (int j = 0; j < width/colorBoxSize; j++) {
thisBlock = color(conversionValuesArray[colorCount], conversionValuesArray[colorCount+1], conversionValuesArray[colorCount+2]);
if(colorCount==0){
clr[0] = conversionValuesArray[colorCount];
clr[1] = conversionValuesArray[colorCount+1];
clr[2] = conversionValuesArray[colorCount+2];
}
if (randomCount > limitFade) {
clrTarget[0] = clr[0];
clrTarget[1] = clr[1];
clrTarget[2] = clr[2];
clr[0] = conversionValuesArray[colorCount];
clr[1] = conversionValuesArray[colorCount+1];
clr[2] = conversionValuesArray[colorCount+2];
limitFade = floor(random(50, 200));
randomCount=0;
}
randomCount+=1;
clrTarget[0] += (clr[0]-clrTarget[0])*(limitFade*0.0001);//(clr[0]-clrTarget[0])*0.001;
clrTarget[1] += (clr[1]-clrTarget[1])*(limitFade*0.0001);
clrTarget[2] += (clr[2]-clrTarget[2])*(limitFade*0.0001);
c1 = color (clrTarget[0], clrTarget[1], clrTarget[2]);
PixelBox temp = new PixelBox(xCount, yCount, conversionValuesArray[colorCount], conversionValuesArray[colorCount+1], conversionValuesArray[colorCount+2], clrTarget[0], clrTarget[1], clrTarget[2]);
pixbox = (PixelBox[])append (pixbox, temp);
//fill(thisBlock);
//rect(xCount+5,yCount+5,pixelSize,pixelSize);
colorCount+=3;
xCount+=colorBoxSize;
}
xCount=width;
} else {
xCount=0;
yCount+=colorBoxSize;
}
//}
} else {
console.log("colorCount = "+colorCount+" & the loop has ended");
console.log("pixbox.length = "+pixbox.length);
makePixel = false;
}
}
void translateColor(){
//clear conversionColorsArray if it is not the first use of translateColor
conversionColorsArray = new float[0];
for (int i = 0; i < height/colorBoxSize; i++) {
for (int j = 0; j < width/colorBoxSize; j++) {
int y = i*colorBoxSize + colorBoxSize/2;
int x = j*colorBoxSize + colorBoxSize/2;
int loc = x + y*width;
loadPixels();
float r = red(img.pixels[loc]);
float g = green(img.pixels[loc]);
float b = blue(img.pixels[loc]);
conversionColorsArray = append(conversionColorsArray, r);
conversionColorsArray = append(conversionColorsArray, g);
conversionColorsArray = append(conversionColorsArray, b);
}
}
matchColors();
}
void matchColors(){
//clear reformedText if it is not the first use of matchColors
reformedText = "";
for(int i = 0; i < conversionColorsArray.length; i++){
for(int j = 0; j < asciiDEC.length; j++){
if(conversionColorsArray[i] == asciiDEC[j]){
//println("asciiCHAR[j] = " +asciiCHAR[j]);
reformedChars = append(reformedChars, asciiCHAR[j]);
}
}
}
checkCodeKey();
}
void checkCodeKey(){
int keyConfirm=0;
for(int i=0; i<codeKeySplit.length; i++){
if(codeKeySplit[i] == reformedChars[i]){
keyConfirm++;
console.log(reformedChars[i]+" __& keyConfirm = "+keyConfirm)
}
}
if(keyConfirm == codeKeySplit.length){
reformedText = join(reformedChars, "");
parseRT = split(reformedText, codeKey);
//String[] parseRT = match(reformedText, "b/'''(.*?)'''b/");
// for (int i=0; i<parseRT.length;i++) {
// console.log("parseRT"+[i]+" = "+parseRT[i]);
// }
}
}
void loadTheImage() {
img = loadImage(filenameSave);
}
void keyReleased() {
if (key == 'm'){
matchCharacters();//function to check text against ascii
}
if (key == 's'){
save("howl2.png");
}
if (key == 't'){
translateColor();
}
if (key == 'r'){
matchColors();
}
}
class PixelBox {
int x = 0;
int y = 0;
float clr1;
float clr2;
float clr3;
float blk1;
float blk2;
float blk3;
PixelBox(int xin, int yin, float clr1in, float clr2in, float clr3in, float blk1in,float blk2in, float blk3in) {
x = xin;
y = yin;
clr1 = clr1in;
clr2 = clr2in;
clr3 = clr3in;
blk1 = blk1in;
blk2 = blk2in;
blk3 = blk3in;
}
void update() {
}
void display() {
fill(blk1, blk2, blk3);
//fill(190,120,140);
rect(x, y, colorBoxSize, colorBoxSize);
fill(clr1, clr2, clr3);
rect(x+5,y+5,pixelSize,pixelSize);
}
}
////////////////////JQUERY FUNCTIONS////////////////////
$(document).ready(function(){
now = new Date();
hour1 = now.getHours();
minute1 = now.getMinutes();
second1 = now.getSeconds();
month1 = now.getMonth()+1;
day1 = now.getDate();
year1 = now.getYear()+ 1900;
timearray = {month1,"_",day1,"_",year1,"_",hour1,"_",minute1,"_",second1,".png"};
//timearray = {month1,day1,year1,hour1,minute1,second1,".png"};
timename = timearray.join("");
//onload, fit giftWrap class to fill window
var windowHeight = $(window).height();
$('.giftWrap').css("height", windowHeight);
//if window is resized, fit giftWrap class to fill new window size
$(window).resize(function() {
windowHeight = (-($(document).width())/2)-60;
$('.giftWrap').css("height", windowHeight);
});
$("#textarea").keyup(function () {
textfill = $(this).val();
typingCount = textfill.split("");
$('#tcounter').html("character count: "+typingCount.length);
//console.log(textfill);
}).keyup();
$("#textarea").keydown(function () {
if (event.keyCode == '13') {
if (event.keyCode == '13') { event.preventDefault(); }
$(this).val($(this).val()+" ");
}
}).keydown();
$("#imageizer").click(function() {
$(".presentText").text(textfill);
allCharzKeyed = codeKey+textfill+codeKey;
allCharz = allCharzKeyed.split("");
allCharzLength = allCharz.length;
console.log("allCharzKeyed = " + allCharzKeyed);
fixit();
//typedString = allCharz.join("");
//matchCharacters(allCharz);
console.log("allCharz = " + allCharz);
});
function fixit() {
for (x=0; x<allCharzLength; x++) {
// replace all the single, double quotes:
if (allCharz[x] == "\""){
allCharz[x] = "\"";
}
}
return allCharz;
}
$('#viewfinder').live('pageshow',function(event){
console.log("pageload");
parseText(allCharz);
});
$('#key').click(function(){
var newKey = $('#keyset').val();
codeKey = newKey;
console.log("newKey = "+newKey);
});
$("#savename").val(timename);
// $('#saver').click(function() {
// filenameSave = $("#savename").val();
// console.log("filenameSave = "+ filenameSave);
// save(filenameSave);
// });
$('#saver').click(function() {
filenameSave = $("#savename").val();
var canvas = document.getElementById("canvas1");
Canvas2Image.saveAsPNG(canvas);
//var img = canvas.toDataURL("image/png");
});
//$('#showThisImage').attr({src: "images/"+filenameSave});
$('#ctt').live('pageshow',function(event){
//loadTheImage();
console.log("this function is broken");
translateColor();
$('#textreadout').val(parseRT[1]);
});
});