forked from 1s-0s/Psychic-Doodle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.js
115 lines (106 loc) · 3.6 KB
/
content.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
console.log("aur kya bolti public? ");
chrome.storage.sync.set({ on: false }, () => {
console.log("running from content");
chrome.runtime.onMessage.addListener(gotMessage);
let spread = 5;
let numDots = 5;
let currColor = "#000000";
let currWeight = 3;
let currOperation = "lineShape";
let begin = true;
// chrome.storage.sync.get(["on"], (result) => {
// on = result.on;
// console.log("inside sketch 0: ", result.on);
// });
function gotMessage(message, sender, sendResponse) {
// console.log("inside got message", message.flag);
// if(message.flag === -1){
// on=message.start;
// }
if (message.flag == 0) currColor = message.color;
else if (message.flag == 1) {
currWeight = 3 * message.weight;
console.log("currWeight: ", currWeight);
} else if (message.flag == 2) {
currOperation = message.shape;
console.log("shape: ", currOperation);
} else if (message.flag == 3) {
currOperation = message.tool;
console.log("tool: ", currOperation);
}
}
// P5.js
let s = (sketch) => {
sketch.setup = () => {
document.body.style["userSelect"] = "none";
let h = document.body.clientHeight;
let c = sketch.createCanvas(sketch.displayWidth, h);
c.position(0, 0);
c.style("pointer-events", "none");
sketch.clear();
};
sketch.mouseClicked = () => {
chrome.storage.sync.get(["on"], (result) => {
begin = result.on;
});
console.log("mouse is clicked0 and begin is ", begin);
if (begin === true) {
console.log("mouse is clicked1 and begin is ", begin);
if (currOperation === "circleShape") {
sketch.ellipse(sketch.mouseX, sketch.mouseY, 200, 200);
} else if (currOperation === "ellipseShape") {
sketch.ellipse(sketch.mouseX, sketch.mouseY, 300, 200);
} else if (currOperation === "triangleShape") {
let x1 = sketch.mouseX;
let y1 = sketch.mouseY;
let x2 = x1 + 100;
let y2 = y1 - 100;
let x3 = x1 + 200;
let y3 = y1;
sketch.triangle(x1, y1, x2, y2, x3, y3);
} else if (currOperation === "squareShape") {
sketch.rect(sketch.mouseX, sketch.mouseY, 200, 200);
}
}
};
sketch.draw = () => {
//chrome.storage.sync.get(["on"], (result) => {
//begin = result.on;
//console.log("drawing0 and begin is ", begin);
if (begin === true) {
//console.log("drawing1 and begin is ", begin);
sketch.stroke(currColor);
sketch.strokeWeight(currWeight);
if (sketch.mouseIsPressed) {
if (currOperation === "lineShape") {
sketch.line(
sketch.mouseX,
sketch.mouseY,
sketch.pmouseX,
sketch.pmouseY
);
}
//USING TOOLS
if (currOperation === "bucketTool") {
sketch.noErase();
sketch.background(currColor);
} else if (currOperation === "eraserTool") {
sketch.clear();
} else if (currOperation === "sprayTool") {
for (let i = 0; i < numDots; i++) {
let x = sketch.mouseX + sketch.random(-spread, spread);
let y = sketch.mouseY + sketch.random(-spread, spread);
sketch.point(x, y);
}
} else if (currOperation === "brushTool") {
//sketch.noErase();
sketch.fill(currColor);
sketch.line(sketch.mouseX, sketch.mouseY, sketch.pmouseX, sketch.pmouseY);
}
}
}
//});
};
};
let myp5 = new p5(s);
});