-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
86 lines (71 loc) · 3.01 KB
/
script.js
File metadata and controls
86 lines (71 loc) · 3.01 KB
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
let lockPosition = 0;
let redLocked, greenLocked, blueLocked;
let red, green, blue;
function main(e) {
//pozycja kursora względem viewportu podana w px
let cursorWidth = e.clientX;
let cursorHeight = e.clientY;
let windowWidth = window.innerWidth;
let windowHeight = window.innerHeight;
//(question)?(result if true):(result is false)
let smallerDimension = (windowHeight < windowWidth) ? windowHeight : windowWidth;
let biggerDimension = (windowHeight > windowWidth) ? windowHeight : windowWidth;
// console.log("w: " + cursorWidth + " h:" + cursorHeight);
document.getElementById("brush").style.top = cursorHeight + "px";
document.getElementById("brush").style.left = cursorWidth + "px";
//Obliczanie dystansu od rogu
//Red = lewy bok
//Green = prawa gora
//Blue = prawy doł
let redDistance = cursorWidth;
// console.log("rD "+redDistance);
let greenDistance = parseInt(Math.sqrt(Math.pow(cursorHeight, 2) + Math.pow(windowWidth - cursorWidth, 2)));
// console.log("gD "+greenDistance);
let blueDistance = parseInt(Math.sqrt(Math.pow(windowHeight - cursorHeight, 2) + Math.pow(windowWidth - cursorWidth, 2)));
// console.log("bD "+blueDistance);
let redColor = 255 - parseInt((redDistance * 255) / biggerDimension);
let greenColor = 255 - parseInt((greenDistance * 255) / smallerDimension);
let blueColor = 255 - parseInt((blueDistance * 255) / smallerDimension);
//zablokowanie koloru po naciśnięciu prawym przyciskiem myszy
if (lockPosition == 0) {
red = (redColor > 0) ? redColor : 0;
green = (greenColor > 0) ? greenColor : 0;
blue = (blueColor > 0) ? blueColor : 0;
} else if (lockPosition == 1) {
red = redLocked;
green = (greenColor > 0) ? greenColor : 0;
blue = (blueColor > 0) ? blueColor : 0;
} else if (lockPosition == 2) {
red = redLocked;
green = greenLocked;
blue = (blueColor > 0) ? blueColor : 0;
} else if (lockPosition == 3) {
red = redLocked;
green = greenLocked;
blue = blueLocked;
}
// console.log(`redP ${red} greenP ${green} blueP ${blue}`);
document.body.style.backgroundColor = `rgb(${red},${green},${blue})`;
document.getElementById("rgbaText").style.color = `rgb(${255-red},${255-green},${255-blue})`;
document.getElementById("rgbaText").innerHTML = `rgb(${red}, ${green}, ${blue})`;
}
function copied() {
let rgbtext = document.getElementById("rgbaText").innerHTML;
//kopiowanie tekstu do schowka
navigator.clipboard.writeText(rgbtext);
document.getElementById("copiedDiv").style.top = "5%";
setTimeout(function () {
document.getElementById("copiedDiv").style.top = "-20%";
}, 2000);
}
function rightClick(e) {
//zapobiega otwieraniu się menu kontekstowego tak jak to jest standardowo
e.preventDefault();
redLocked = red;
blueLocked = blue;
greenLocked = green;
lockPosition++;
if (lockPosition > 3) {
lockPosition = 0;
}
}