-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsketch2.js
100 lines (87 loc) · 3.2 KB
/
sketch2.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
//------------------- This Sketch Is For Viewing Submissions ------------------------//
//Stores What Sent
let undoHistoryX,
undoHistoryY,
r,
g,
b,
lastradius,
downloadedCanvasX,
downloadedCanvasY,
canvas1;
let username = [];
let database; //Access The Firebase's Database
let ref; //Reference To The Database
let keys; //Stores Database's Keys
let dataList; //Stores Datalist
let colorList = ["#44e2a0",
"#c23d",
"#552ce7",
"#eeb902",
"#2b7e1c",
"#159d98",
"#b6dd26",
"#9b7a19",
"#18b797",
"#772211",
"#9938a4",
"#6282d2",
"#f13fe1",
"#000000"];
//----------------------------------------------- Setup Function
function setup(){
database = firebase.database();
ref = database.ref('gifts/');
ref.on('value',gotData,errorData);
}
//----------------------------------------------- Got Data Function
function gotData(data){
username = [];
dataList = data.val();
keys = Object.keys(dataList);
for(var i = keys.length - 1; i >= 0 ;i--){
//Showing Username
var k = keys[i];
username.unshift(dataList[k].username); // All I Need In This Function
//Creating List Of Username:
seplink = createDiv();
seplink.addClass("seplink");
var usernameAhref = createA('#',dataList[k].username);
usernameAhref.style("color",random(colorList));
seplink.child(usernameAhref)
usernameAhref.mousePressed(printLink);
}
document.getElementById("Header").innerHTML = "Click On Any Of The Link To View Submission";
}
//----------------------------------------------- Error In Getting Data Function
function errorData(err){
document.getElementById("Header").innerHTML = "An Error Occured [!]";
}
//----------------------------------------------- Printing Links & Drawing Canvas
function printLink(){
document.getElementById("Header").innerHTML = "By " + this.html();
console.log(this.html());
var clickKey = keys[username.indexOf(this.html())];
var oneDrawingRef = database.ref('gifts/' + clickKey);
oneDrawingRef.on('value',function(data){
//Storing All Data
undoHistoryX = dataList[clickKey].drawX;
undoHistoryY = dataList[clickKey].drawY;
r = dataList[clickKey].redChannel;
g = dataList[clickKey].greenChannel;
b = dataList[clickKey].blueChannel;
lastradius = dataList[clickKey].radius;
downloadedCanvasX = dataList[clickKey].canvasX;
downloadedCanvasY = dataList[clickKey].canvasY;
canvas1 = createCanvas(downloadedCanvasX,downloadedCanvasY);
canvas1.parent('#sketch2container');
canvas1.background(0);
for(var i = undoHistoryX.length - 1; i >= 0; i--){
canvas1.stroke(r[i],g[i],b[i]);
canvas1.strokeWeight(lastradius[i]);
for(var j = 0; j < undoHistoryX[i].length; j++){
canvas1.line(undoHistoryX[i][j],undoHistoryY[i][j],undoHistoryX[i][j+1],undoHistoryY[i][j+1]);
}
}
},errorData);
}