-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0aeaa3b
commit 30c42ce
Showing
3 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,52 @@ | ||
const canvas = document.getElementById("black-board"); | ||
const boardColorInp = document.getElementById("board-color"); | ||
const penColorInp = document.getElementById("pen-color"); | ||
const penThicknessInp = document.getElementById("pen-thickness"); | ||
const eraserBtn = document.getElementById("eraser-btn"); | ||
const eraserThicknessInp = document.getElementById("eraser-thickness"); | ||
|
||
let isEraserEnabled = false; | ||
|
||
// Change board color | ||
boardColorInp.addEventListener("change", (e) => { | ||
const color = e.target.value; | ||
canvas.style.backgroundColor = color; | ||
}); | ||
|
||
// Change pen color and thickness | ||
penColorInp.addEventListener("change", (e) => { | ||
const color = e.target.value; | ||
const context = canvas.getContext("2d"); | ||
context.strokeStyle = color; | ||
}); | ||
|
||
// Change pen thickness | ||
penThicknessInp.addEventListener("input", (e) => { | ||
const thickness = e.target.value; | ||
const context = canvas.getContext("2d"); | ||
context.lineWidth = thickness; | ||
}); | ||
|
||
// Toggle eraser mode | ||
eraserBtn.addEventListener("click", () => { | ||
isEraserEnabled = !isEraserEnabled; | ||
const context = canvas.getContext("2d"); | ||
|
||
if (isEraserEnabled) { | ||
context.strokeStyle = "#FFFFFF"; // Change to background color for erasing | ||
eraserBtn.textContent = "Disable Eraser"; | ||
} else { | ||
context.strokeStyle = penColorInp.value; // Switch back to pen color | ||
eraserBtn.textContent = "Enable Eraser"; | ||
} | ||
}); | ||
|
||
// Change eraser thickness | ||
eraserThicknessInp.addEventListener("input", (e) => { | ||
const thickness = e.target.value; | ||
const context = canvas.getContext("2d"); | ||
|
||
// Apply eraser thickness | ||
context.lineWidth = thickness; | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters