-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
217 lines (192 loc) · 5.59 KB
/
script.js
File metadata and controls
217 lines (192 loc) · 5.59 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
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
const text =
"Bienvenue sur le r/place organisé par Artic.\n- Clic droit/maintenir appuyé = copier la couleur.\n- Molette/écarter les doigts = zoom.\n- Clic gauche/click = placement de son pixel.\n- 1 seconde entre chaque pixel.";
alert(text);
// creation du tableau
const grid = document.querySelector(".grid");
var socket = io("https://rplace-server-side-margotictaclab.replit.app/");
// var socket = io("https://rplace-ServerSide.rafaeldimitrov.repl.co");
for (let i = 0; i < 10000; i++) {
let span = document.createElement("span");
span.setAttribute("id", "span_" + i);
grid.appendChild(span);
}
//choix couleur
let colorSelect = "#000000";
let red = document.getElementById("red");
let orange = document.getElementById("orange");
let yellow = document.getElementById("yellow");
let dark_green = document.getElementById("dark_green");
let green = document.getElementById("green");
let blue_marin = document.getElementById("blue_marin");
let cyan = document.getElementById("cyan");
let turquoise = document.getElementById("turquoise");
let purple = document.getElementById("purple");
let violette = document.getElementById("violette");
let pink = document.getElementById("pink");
let brown = document.getElementById("brown");
let black = document.getElementById("black");
let grey = document.getElementById("grey");
let white = document.getElementById("white");
let lastSelectedColor = "";
red.onclick = function () {
colorSelect = "#ff4500";
whatColorDidISelect(red);
// alert(colorSelect);
};
orange.onclick = function () {
colorSelect = "#ffa800";
whatColorDidISelect(orange);
// alert(colorSelect);
};
yellow.onclick = function () {
colorSelect = "#ffd635";
whatColorDidISelect(yellow);
// alert(colorSelect);
};
dark_green.onclick = function () {
colorSelect = "#00a368";
whatColorDidISelect(dark_green);
// alert(colorSelect);
};
green.onclick = function () {
colorSelect = "#7eed56";
whatColorDidISelect(green);
// alert(colorSelect);
};
blue_marin.onclick = function () {
colorSelect = "#2450a4";
whatColorDidISelect(blue_marin);
// alert(colorSelect);
};
cyan.onclick = function () {
colorSelect = "#3690ea";
whatColorDidISelect(cyan);
// alert(colorSelect);
};
turquoise.onclick = function () {
colorSelect = "#51e9f4";
whatColorDidISelect(turquoise);
// alert(colorSelect);
};
purple.onclick = function () {
colorSelect = "#811e9f";
whatColorDidISelect(purple);
// alert(colorSelect);
};
violette.onclick = function () {
colorSelect = "#b44ec0";
whatColorDidISelect(violette);
// alert(colorSelect);
};
pink.onclick = function () {
colorSelect = "#ff99aa";
whatColorDidISelect(pink);
// alert(colorSelect);
};
brown.onclick = function () {
colorSelect = "#9c6926";
whatColorDidISelect(brown);
// alert(colorSelect);
};
black.onclick = function () {
colorSelect = "#000000";
whatColorDidISelect(black);
// alert(colorSelect);
};
grey.onclick = function () {
colorSelect = "#898d90";
whatColorDidISelect(grey);
// alert(colorSelect);
};
white.onclick = function () {
colorSelect = "#ffffff";
whatColorDidISelect(white);
// alert(colorSelect);
};
function whatColorDidISelect(clickedColor) {
if (lastSelectedColor) {
lastSelectedColor.classList.remove("color-selected");
}
clickedColor.classList.add("color-selected");
lastSelectedColor = clickedColor;
// alert(lastSelectedColor);
}
//copie couleur
//modif des pixels
function updateGrid(spanId, color) {
updatedPixel = document.getElementById(spanId);
updatedPixel.style.background = color;
}
let timerOrNot = false;
const spans = document.querySelectorAll(".grid span");
spans.forEach((span) => {
span.addEventListener("click", (e) => {
if (timerOrNot == false) {
e.currentTarget.style.background = colorSelect;
let modifData = { [e.currentTarget.id] : colorSelect };
console.log(modifData);
socket.emit("modifPixel", modifData);
timerOrNot = true;
timer();
};
});
//copie de la couleur
span.addEventListener("contextmenu", (e) => {
let clickedElementColor = window.getComputedStyle(
e.currentTarget,
).backgroundColor;
// console.log(rgbToHex(clickedElementColor));
colorSelect = rgbToHex(clickedElementColor);
e.preventDefault();
});
// console.log(timerOrNot);
});
function timer() {
if (timerOrNot == true) {
setTimeout(() => {
timerOrNot = false;
// console.log("Nouvelle valeur :", timerOrNot);
}, 1000);
}
}
//convertisseur rgb to hex(chat gpt)
function rgbToHex(rgb) {
// Séparer les composantes R, G, et B
var rgbArray = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
// Convertir les composantes en valeurs hexadécimales
var hex =
"#" +
componentToHex(rgbArray[1]) +
componentToHex(rgbArray[2]) +
componentToHex(rgbArray[3]);
return hex;
}
function componentToHex(component) {
var hex = parseInt(component, 10).toString(16);
return hex.length == 1 ? "0" + hex : hex;
}
//zoom
let zoomLevel = 1;
document.getElementById("zoomedDiv").addEventListener("wheel", function (e) {
e.preventDefault();
if (e.deltaY < 0) {
// Zoom avant (augmentation du zoomLevel)
zoomLevel += 0.1;
} else {
// Zoom arrière (diminution du zoomLevel)
zoomLevel = Math.max(zoomLevel - 0.1, 0.1);
}
updateZoom();
});
function updateZoom() {
document.getElementById("zoomedDiv").style.transform =
"scale(" + zoomLevel + ")";
}
// const chat_interface = readline.createInterface({
// input: process.stdin,
// output: process.stdout,
// });
// chat_interface.question("> ", function (message) {
// console.log(message);
// socket.emit("message", message);
// });