conditions_better_with_eraser
parent
db0fffc829
commit
92d6731862
|
@ -54,6 +54,7 @@ import Layout from '../../layouts/Layout.astro';
|
||||||
let brushSize = 10; // Default brush size
|
let brushSize = 10; // Default brush size
|
||||||
let customCursor;
|
let customCursor;
|
||||||
const cursorSizeMultiplier = 1;
|
const cursorSizeMultiplier = 1;
|
||||||
|
let isErasing = false;
|
||||||
|
|
||||||
function preload() {
|
function preload() {
|
||||||
this.load.image('outline', assetsList.image);
|
this.load.image('outline', assetsList.image);
|
||||||
|
@ -87,14 +88,14 @@ import Layout from '../../layouts/Layout.astro';
|
||||||
colorPicker.className = 'color-picker';
|
colorPicker.className = 'color-picker';
|
||||||
document.body.appendChild(colorPicker);
|
document.body.appendChild(colorPicker);
|
||||||
colorPicker.style.position = 'absolute';
|
colorPicker.style.position = 'absolute';
|
||||||
// colorPicker.textContent = 'Clear';
|
|
||||||
colorPicker.style.top = '10%';
|
colorPicker.style.top = '10%';
|
||||||
colorPicker.style.left = '20px';
|
colorPicker.style.left = '20px';
|
||||||
colorPicker.style.width = '38px';
|
colorPicker.style.width = '38px';
|
||||||
colorPicker.style.height = '38px';
|
colorPicker.style.height = '38px';
|
||||||
// colorPicker.style.borderRadius = '50%';
|
|
||||||
colorPicker.addEventListener('input', (event) => {
|
colorPicker.addEventListener('input', (event) => {
|
||||||
selectedColor = event.target.value; // Update selectedColor
|
if (!isErasing) {
|
||||||
|
selectedColor = event.target.value; // Update selectedColor if not erasing
|
||||||
|
}
|
||||||
});
|
});
|
||||||
const colors = ['#ff0000', '#00ff00', '#0000ff', '#ffff00', '#ff00ff', '#00ffff'];
|
const colors = ['#ff0000', '#00ff00', '#0000ff', '#ffff00', '#ff00ff', '#00ffff'];
|
||||||
const buttonSize = 40;
|
const buttonSize = 40;
|
||||||
|
@ -169,6 +170,33 @@ import Layout from '../../layouts/Layout.astro';
|
||||||
clearDrawing();
|
clearDrawing();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const eraserButton = document.createElement('button');
|
||||||
|
eraserButton.textContent = 'Eraser';
|
||||||
|
document.body.appendChild(eraserButton);
|
||||||
|
eraserButton.style.position = 'absolute';
|
||||||
|
eraserButton.style.top = '10%';
|
||||||
|
eraserButton.style.left = '80px';
|
||||||
|
eraserButton.style.backgroundColor = 'white'; // Background color for eraser button
|
||||||
|
eraserButton.style.color = 'black'; // Text color for eraser button
|
||||||
|
eraserButton.style.padding = '10px 20px';
|
||||||
|
eraserButton.style.fontSize = '16px';
|
||||||
|
eraserButton.style.fontWeight = 'bold';
|
||||||
|
eraserButton.style.borderRadius = '50%';
|
||||||
|
eraserButton.style.boxShadow = '5px 10px 15px #aaa';
|
||||||
|
|
||||||
|
// Toggle erasing mode when the eraser button is clicked
|
||||||
|
eraserButton.addEventListener('click', () => {
|
||||||
|
isErasing = !isErasing;
|
||||||
|
if (isErasing) {
|
||||||
|
eraserButton.style.backgroundColor = 'red'; // Update eraser button color to indicate erasing mode
|
||||||
|
eraserButton.style.color = 'white';
|
||||||
|
} else {
|
||||||
|
// Return to drawing mode
|
||||||
|
eraserButton.style.backgroundColor = 'white'; // Restore eraser button color
|
||||||
|
eraserButton.style.color = 'black';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
this.input.on('pointerdown', () => {
|
this.input.on('pointerdown', () => {
|
||||||
isDrawing = true;
|
isDrawing = true;
|
||||||
|
@ -214,13 +242,22 @@ import Layout from '../../layouts/Layout.astro';
|
||||||
}
|
}
|
||||||
|
|
||||||
function startDrawing(x, y) {
|
function startDrawing(x, y) {
|
||||||
graphics.lineStyle(brushSize * 2, Phaser.Display.Color.HexStringToColor(selectedColor).color);
|
if (!isErasing) {
|
||||||
|
graphics.lineStyle(brushSize * 2, Phaser.Display.Color.HexStringToColor(selectedColor).color);
|
||||||
|
} else {
|
||||||
|
graphics.lineStyle(brushSize * 2, 0xffffff, 1); // Set a white color to clear lines (full opacity)
|
||||||
|
}
|
||||||
graphics.beginPath();
|
graphics.beginPath();
|
||||||
graphics.moveTo(x, y);
|
graphics.moveTo(x, y);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function continueDrawing(x, y) {
|
function continueDrawing(x, y) {
|
||||||
graphics.lineTo(x, y);
|
if (!isErasing) {
|
||||||
|
graphics.lineTo(x, y); // Drawing
|
||||||
|
} else {
|
||||||
|
graphics.lineTo(x, y); // Erasing by drawing with a white line
|
||||||
|
}
|
||||||
graphics.strokePath();
|
graphics.strokePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue