forked from yashrajbharti/gradients-creator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
129 lines (117 loc) · 3.18 KB
/
Copy pathscript.js
File metadata and controls
129 lines (117 loc) · 3.18 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
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
//Some classes and html functions need to determine a constant
const css = document.querySelector(".codess"); // color code
const color1 = document.querySelector(".color1"); // 1st color
const color2 = document.querySelector(".color2"); // 2nd color
const bodys = document.getElementById("gradient"); // color display
const linearDirection = document.getElementsByName("toDirection")[0]; //Select box
const cancel = document.querySelector(".cancel");
//displays default CSS RGBA values for linear-gradient
function currentSettings() {
const CSSprop = window
.getComputedStyle(bodys, null)
.getPropertyValue("background-image");
// console.log(CSSprop)
css.textContent = "background-image:" + CSSprop;
}
currentSettings();
//You have to make arrangements to see the color code in the display
function returnColor() {
bodys.style.backgroundImage =
"linear-gradient(" +
linearDirection.value +
", " +
color1.value +
"," +
color2.value +
")";
currentSettings();
}
css.addEventListener("input", () => {
if (
css.textContent.includes("background-color") &&
css.textContent.includes("background-image")
) {
bodys.style.backgroundColor = css.textContent.split(/[:;]/)[1];
bodys.style.backgroundImage = css.textContent.split(/[:;]/)[3];
} else bodys.style.backgroundImage = css.textContent.split(/[:;]/)[1];
});
document.querySelector('select[name="toDirection"]').onchange = returnColor;
color1.addEventListener("input", returnColor);
color2.addEventListener("input", returnColor);
cancel.style.display = "none";
const fileTag = document.getElementById("filetag"),
preview = document.getElementById("preview");
fileTag.addEventListener("change", function () {
changeImage(this);
});
function changeImage(input) {
let reader;
if (input.files && input.files[0]) {
reader = new FileReader();
reader.onload = function (e) {
preview.setAttribute("src", e.target.result);
preview.style.display = "block";
cancel.style.display = "block";
};
reader.readAsDataURL(input.files[0]);
}
}
function hidestuff() {
cancel.style.display = "none";
preview.style.display = "none";
}
let up = false,
right = false,
down = false,
left = false,
x = window.innerWidth / 2 - 130 / 2,
y = window.innerHeight / 2 - 130 / 2;
document.addEventListener("keydown", press);
function press(e) {
if (e.code === "KeyW" /* w */) {
up = true;
}
if (e.code === "KeyD" /* d */) {
right = true;
}
if (e.code === "KeyS" /* s */) {
down = true;
}
if (e.code === "KeyA" /* a */) {
left = true;
}
}
document.addEventListener("keyup", release);
function release(e) {
if (e.code === "KeyW" /* w */) {
up = false;
}
if (e.code === "KeyD" /* d */) {
right = false;
}
if (e.code === "KeyS" /* s */) {
down = false;
}
if (e.code === "KeyA" /* a */) {
left = false;
}
}
function gameLoop() {
const div = document.querySelector("#move");
if (up) {
y = y - 20;
}
if (right) {
x = x + 20;
}
if (down) {
y = y + 20;
}
if (left) {
x = x - 20;
}
div.style.left = x + "px";
div.style.top = y + "px";
window.requestAnimationFrame(gameLoop);
}
window.requestAnimationFrame(gameLoop);