-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpaint.html
343 lines (299 loc) · 12.7 KB
/
paint.html
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<title>пейнтик</title>
<link rel="stylesheet" href="https://unpkg.com/7.css">
<style>
body, html {
color: #000000;
}
#tool-indicator {
font-family: 'Trebuchet MS', Arial, sans-serif;
color: #FFFFFF;
}
#widthInput {
width: 60px;
}
#heightInput {
width: 60px;
}
#canvas {
border: 1px solid #000;
}
#loading-window {
border-radius: 10px; /* Скруглики */
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: #B3D194;
display: flex;
justify-content: center;
align-items: center;
z-index: 10; /* Убедитесь, что loading window находится выше других элементов */
}
#loading-text {
font-size: 19px;
color: initial;
}
#loading-progress {
border-radius: 3.5px; /* Скругление углов */
width: 150px;
height: 10px;
background-color: #E1EBF4;
border: 1px solid #000;
}
#loading-progress-bar {
border-radius: 3.5px; /* Скругление углов */
width: 0px;
height: 100%;
background-color: #97BB71;
transition: width 1s linear;
}
#start-button {
position: absolute;
bottom: 30px;
left: 30px;
cursor: pointer;
z-index: 11; /* Убедитесь, что кнопка начать находится выше loading window */
}
</style>
</head>
<body>
<div id="tool-indicator">Выбран инструмент: кисть</div>
<div id="loading-window">
<div id="loading-text">Загрузка...ㅤ</div>
<div id="loading-progress">
<div id="loading-progress-bar"></div>
</div>
</div>
<button id="start-button" hidden>Начать!</button>
<script>
const loadingWindow = document.getElementById('loading-window');
const startButton = document.getElementById('start-button');
const progressBar = document.getElementById('loading-progress-bar');
let progress = 0;
const timer = setInterval(() => {
progress += 1;
progressBar.style.width = progress + '%'; // Конкатенация строки используется для обновления ширины
if (progress >= 100) {
clearInterval(timer);
setTimeout(() => {
loadingWindow.hidden = true;
startButton.hidden = false;
}, 200);
}
}, 100);
startButton.addEventListener('click', () => {
initiatePaintApp();
loadingWindow.remove(); // Удаляем только окно загрузки
startButton.remove(); // Удаляем кнопку "Начать"
});
function initiatePaintApp() {
const body = document.body;
const canvas = document.createElement('canvas');
canvas.id = 'paintCanvas';
canvas.width = 100;
canvas.height = 100;
body.appendChild(canvas);
const ctx = canvas.getContext('2d');
ctx.fillStyle = '#FFFFFF';
ctx.fillRect(0, 0, canvas.width, canvas.height);
// ... Ваш код для создания интерфейса ...
// Кнопки для изменения размера холста
const resizeButtons = ['50x50','100x100', '200x100', '200x150'];
resizeButtons.forEach(size => {
const button = document.createElement('button');
button.innerText = size;
button.addEventListener('click', () => {
const [width, height] = size.split('x');
canvas.width = width;
canvas.height = height;
// Перезаполняем фон после изменения размера
ctx.fillStyle = '#FFFFFF';
ctx.fillRect(0, 0, canvas.width, canvas.height);
});
body.appendChild(button);
});
// Добавляем текстовые поля для ввода размеров и кнопку для применения
const widthHeightContainer = document.createElement('div');
widthHeightContainer.innerHTML = `
<label for="widthInput"> </label>
<input type="number" id="widthInput" placeholder="Ширина">
<label for="heightInput"> </label>
<input type="number" id="heightInput" placeholder="Высота">
<button id="resizeButton">Применить</button>
`;
body.appendChild(widthHeightContainer);
// Получаем элементы текстовых полей и кнопки
const widthInput = document.getElementById('widthInput');
const heightInput = document.getElementById('heightInput');
const resizeButton = document.getElementById('resizeButton');
// Функция для изменения размера холста
function resizeCanvas() {
const width = widthInput.value;
const height = heightInput.value;
if (width && height) {
canvas.width = width;
canvas.height = height;
// Перезаполняем фон после изменения размера
ctx.fillStyle = '#FFFFFF';
ctx.fillRect(0, 0, canvas.width, canvas.height);
} else {
alert('Ой! Кажется ты ввёл не верные значения ширины и/или высоты! Введи что-то верное, пожалуйста :3');
}
}
// Обработчик события клика для кнопки
resizeButton.addEventListener('click', resizeCanvas);
// Выбор размера кисти
const brushSizeLabel = document.createElement('label');
brushSizeLabel.innerText = 'Размеры кисточки:';
body.appendChild(brushSizeLabel);
const brushSizeSelect = document.createElement('select');
brushSizeSelect.id = 'brushSize';
['Маленькая', 'Средняя', 'Большая'].forEach((size, index) => {
const option = document.createElement('option');
option.value = index === 0 ? '5' : (index === 1 ? '10' : '20');
option.innerText = size;
if (index === 1) option.selected = true;
brushSizeSelect.appendChild(option);
});
body.appendChild(brushSizeSelect);
// Выбор цвета
const colorPicker = document.createElement('input');
colorPicker.type = 'color';
colorPicker.id = 'colorPicker';
body.appendChild(colorPicker);
// Кнопка кисти
const brushButton = document.createElement('button');
brushButton.innerText = 'Кисть';
brushButton.id= 'brushButton';
body.appendChild(brushButton);
// Кнопка ластика
const eraserButton = document.createElement('button');
eraserButton.innerText = 'Ластик';
eraserButton.id= 'eraserButton';
body.appendChild(eraserButton);
// Кнопка очистки холста
const clearButton = document.createElement('button');
clearButton.innerText = 'Очистить холст';
clearButton.addEventListener('click', () => {
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = '#FFFFFF';
ctx.fillRect(0, 0, canvas.width, canvas.height);
});
body.appendChild(clearButton);
// Кнопка сохранения изображения
const saveButton = document.createElement('button');
saveButton.innerText = 'Сохранить изображение';
saveButton.addEventListener('click', () => {
const image = canvas.toDataURL('image/png').replace('image/png', 'image/octet-stream');
const link = document.createElement('a');
link.download = 'рисунок.png';
link.href = image;
link.click();
});
body.appendChild(saveButton);
// Функция для обновления мини-текста с названием текущего инструмента
function updateToolIndicator(toolName) {
document.getElementById('tool-indicator').textContent = `Выбран инструмент: ${toolName}`;
}
// Обработчики событий для кнопок инструментов
brushButton.addEventListener('click', function() {
activateBrush();
});
eraserButton.addEventListener('click', function() {
activateEraser();
});
// Функции для обработки сенсорных событий
function touchStart(e) {
e.preventDefault();
startPosition(getTouchPos(canvas, e));
}
function touchEnd(e) {
e.preventDefault();
finishedPosition();
}
function touchMove(e) {
e.preventDefault();
draw(getTouchPos(canvas, e));
}
// Функция для получения позиции касания
function getTouchPos(canvasDom, touchEvent) {
var rect = canvasDom.getBoundingClientRect();
return {
x: touchEvent.touches[0].clientX - rect.left,
y: touchEvent.touches[0].clientY - rect.top
};
}
// ... добавьте обработчики для других инструментов по аналогии
// Элемент HTML для индикатора инструмента
// Убедитесь, что этот элемент добавлен в ваш HTML
let painting = false;
let currentColor = '#000000'; // Переменная для хранения текущего цвета
function startPosition(pos) {
painting = true;
draw(pos);
}
function finishedPosition() {
painting = false;
ctx.beginPath();
ctx.globalCompositeOperation = 'source-over';
}
function getTouchPos(canvasDom, touchEvent) {
var rect = canvasDom.getBoundingClientRect();
return {
x: touchEvent.touches[0].clientX - rect.left,
y: touchEvent.touches[0].clientY - rect.top
};
}
function draw(pos) {
if (!painting) return;
ctx.lineWidth = document.getElementById('brushSize').value;
ctx.lineCap = 'round';
ctx.strokeStyle = document.getElementById('colorPicker').value;
ctx.lineTo(pos.x, pos.y);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(pos.x, pos.y);
}
// Функция для активации кисти
function activateBrush() {
console.log("прохладно... * пссссс * АШУТ ОТКРЫВАЙ ПАРАШУТ АЖУАЛФЗЙОУКПДЖЩЖШОУПРЩГШПКРШГУУДЦАДШШИОЙЦАУШТЖОУПТШГЖПУЦШРЖО")
colorPicker.value = currentColor; // Восстановление сохранённого цвета
colorPicker.disabled = false; // Разблокировка элемента выбора цвета
updateToolIndicator('кисть'); // Обновление индикатора инструмента
// Дополнительный код для активации кисти...
}
// Функция для активации ластика
function activateEraser() {
currentColor = colorPicker.value; // Сохранение текущего цвета
colorPicker.value = '#FFFFFF'; // Установка белого цвета для ластика
colorPicker.disabled = true; // Блокировка элемента выбора цвета
updateToolIndicator('ластик'); // Обновление индикатора инструмента
// Дополнительный код для активации ластика...
}
// Обработчики событий для мыши
canvas.addEventListener('mousedown', e => startPosition({x: e.offsetX, y: e.offsetY}));
canvas.addEventListener('mouseup', finishedPosition);
canvas.addEventListener('mousemove', e => draw({x: e.offsetX, y: e.offsetY}));
// Обработчики событий для сенсорных устройств
canvas.addEventListener('touchstart', function(e) {
e.preventDefault();
startPosition(getTouchPos(canvas, e));
}, false);
canvas.addEventListener('touchend', function(e) {
e.preventDefault();
finishedPosition();
}, false);
canvas.addEventListener('touchmove', function(e) {
e.preventDefault();
draw(getTouchPos(canvas, e));
}, false);
// ... Остальной код ...
}
</script>
</body>
</html>