-
Notifications
You must be signed in to change notification settings - Fork 164
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
0ceb11b
commit bf4c447
Showing
7 changed files
with
186 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Doodling Game | ||
|
||
A simple doodling game where users can draw on a canvas, change colors, and adjust the brush size. This game supports both mouse and touch inputs, making it suitable for both desktop and mobile devices. | ||
|
||
## Features | ||
|
||
- Draw on the canvas using mouse or touch inputs. | ||
- Change the color of the brush using a color picker. | ||
- Adjust the brush size using a range slider. | ||
- Clear the canvas with a single click. | ||
|
||
## Demo | ||
|
||
![Doodling Game Demo](demo.gif) | ||
|
||
## How to Run | ||
|
||
1. Clone the repository or download the files. | ||
2. Open the `index.html` file in your preferred web browser. | ||
|
||
## Files | ||
|
||
- `index.html`: The main HTML file containing the structure of the doodling game. | ||
- `styles.css`: The CSS file for styling the doodling game. | ||
- `script.js`: The JavaScript file containing the logic for the doodling game. | ||
|
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Doodling Game</title> | ||
<link rel="stylesheet" href="styles.css"> | ||
</head> | ||
<body> | ||
<div class="toolbar"> | ||
<button id="clear">Clear</button> | ||
<input type="color" id="colorPicker"> | ||
<input type="range" id="sizePicker" min="1" max="10" value="5"> | ||
</div> | ||
<canvas id="drawingCanvas"></canvas> | ||
<script src="script.js"></script> | ||
</body> | ||
</html> |
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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
const canvas = document.getElementById('drawingCanvas'); | ||
const ctx = canvas.getContext('2d'); | ||
|
||
canvas.width = window.innerWidth * 0.8; | ||
canvas.height = window.innerHeight * 0.8; | ||
|
||
let painting = false; | ||
let color = '#000'; | ||
let lineWidth = 5; | ||
|
||
function startPosition(e) { | ||
painting = true; | ||
draw(e); | ||
} | ||
|
||
function endPosition() { | ||
painting = false; | ||
ctx.beginPath(); | ||
} | ||
|
||
function draw(e) { | ||
if (!painting) return; | ||
|
||
ctx.lineWidth = lineWidth; | ||
ctx.lineCap = 'round'; | ||
ctx.strokeStyle = color; | ||
|
||
ctx.lineTo(e.clientX - canvas.offsetLeft, e.clientY - canvas.offsetTop); | ||
ctx.stroke(); | ||
ctx.beginPath(); | ||
ctx.moveTo(e.clientX - canvas.offsetLeft, e.clientY - canvas.offsetTop); | ||
} | ||
|
||
canvas.addEventListener('mousedown', startPosition); | ||
canvas.addEventListener('mouseup', endPosition); | ||
canvas.addEventListener('mousemove', draw); | ||
|
||
// Touch support for mobile devices | ||
canvas.addEventListener('touchstart', (e) => { | ||
const touch = e.touches[0]; | ||
const mouseEvent = new MouseEvent('mousedown', { | ||
clientX: touch.clientX, | ||
clientY: touch.clientY | ||
}); | ||
canvas.dispatchEvent(mouseEvent); | ||
}); | ||
|
||
canvas.addEventListener('touchend', () => { | ||
const mouseEvent = new MouseEvent('mouseup', {}); | ||
canvas.dispatchEvent(mouseEvent); | ||
}); | ||
|
||
canvas.addEventListener('touchmove', (e) => { | ||
const touch = e.touches[0]; | ||
const mouseEvent = new MouseEvent('mousemove', { | ||
clientX: touch.clientX, | ||
clientY: touch.clientY | ||
}); | ||
canvas.dispatchEvent(mouseEvent); | ||
}); | ||
|
||
document.getElementById('clear').addEventListener('click', () => { | ||
ctx.clearRect(0, 0, canvas.width, canvas.height); | ||
}); | ||
|
||
document.getElementById('colorPicker').addEventListener('change', (e) => { | ||
color = e.target.value; | ||
}); | ||
|
||
document.getElementById('sizePicker').addEventListener('change', (e) => { | ||
lineWidth = e.target.value; | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
body { | ||
margin: 0; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
background-color: #f0f0f0; | ||
} | ||
|
||
.toolbar { | ||
margin: 20px; | ||
} | ||
|
||
#drawingCanvas { | ||
border: 1px solid #000; | ||
background-color: #fff; | ||
} |
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