Skip to content

Commit 2736fc7

Browse files
authored
Add files via upload
This is Drawing App I made it from HTML CSS & Javascript
0 parents  commit 2736fc7

File tree

3 files changed

+155
-0
lines changed

3 files changed

+155
-0
lines changed

index.html

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<link rel="stylesheet" href="style.css" />
7+
<title>Drawing App</title>
8+
</head>
9+
<body>
10+
<canvas id="canvas" width="1100" height="600"></canvas>
11+
<div class="toolbox">
12+
<button id="decrease">-</button>
13+
<span id="size">10</span>
14+
<button id="increase">+</button>
15+
<input type="color" id="color">
16+
<button id="clear">X</button>
17+
</div>
18+
19+
<!-- Developed By Qavi Shaikh -->
20+
21+
<script src="script.js"></script>
22+
</body>
23+
</html>

script.js

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
const canvas = document.getElementById('canvas');
2+
const increaseBtn = document.getElementById('increase');
3+
const decreaseBtn = document.getElementById('decrease');
4+
const sizeEL = document.getElementById('size');
5+
const colorEl = document.getElementById('color');
6+
const clearEl = document.getElementById('clear');
7+
8+
const ctx = canvas.getContext('2d');
9+
10+
let size = 10
11+
let isPressed = false
12+
colorEl.value = 'black'
13+
let color = colorEl.value
14+
let x
15+
let y
16+
17+
canvas.addEventListener('mousedown', (e) => {
18+
isPressed = true
19+
20+
x = e.offsetX
21+
y = e.offsetY
22+
})
23+
24+
document.addEventListener('mouseup', (e) => {
25+
isPressed = false
26+
27+
x = undefined
28+
y = undefined
29+
})
30+
31+
canvas.addEventListener('mousemove', (e) => {
32+
if(isPressed) {
33+
const x2 = e.offsetX
34+
const y2 = e.offsetY
35+
36+
drawCircle(x2, y2)
37+
drawLine(x, y, x2, y2)
38+
39+
x = x2
40+
y = y2
41+
}
42+
})
43+
44+
function drawCircle(x, y) {
45+
ctx.beginPath();
46+
ctx.arc(x, y, size, 0, Math.PI * 2)
47+
ctx.fillStyle = color
48+
ctx.fill()
49+
}
50+
51+
function drawLine(x1, y1, x2, y2) {
52+
ctx.beginPath()
53+
ctx.moveTo(x1, y1)
54+
ctx.lineTo(x2, y2)
55+
ctx.strokeStyle = color
56+
ctx.lineWidth = size * 2
57+
ctx.stroke()
58+
}
59+
60+
function updateSizeOnScreen() {
61+
sizeEL.innerText = size
62+
}
63+
64+
increaseBtn.addEventListener('click', () => {
65+
size += 5
66+
67+
if(size > 50) {
68+
size = 50
69+
}
70+
71+
updateSizeOnScreen()
72+
})
73+
74+
decreaseBtn.addEventListener('click', () => {
75+
size -= 5
76+
77+
if(size < 5) {
78+
size = 5
79+
}
80+
81+
updateSizeOnScreen()
82+
})
83+
84+
colorEl.addEventListener('change', (e) => color = e.target.value)
85+
86+
clearEl.addEventListener('click', () => ctx.clearRect(0,0, canvas.width, canvas.height))

style.css

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap');
2+
3+
* {
4+
box-sizing: border-box;
5+
}
6+
7+
body {
8+
background-color: #f5f5f5;
9+
font-family: 'Roboto', sans-serif;
10+
display: flex;
11+
flex-direction: column;
12+
align-items: center;
13+
justify-content: center;
14+
height: 100vh;
15+
margin: 0;
16+
}
17+
18+
canvas {
19+
border: 2px solid rgb(12, 149, 248);
20+
}
21+
22+
.toolbox {
23+
background-color: rgb(12, 149, 248);;
24+
border: 1px solid slateblue;
25+
display: flex;
26+
width: 1000px;
27+
padding: 1rem;
28+
}
29+
30+
.toolbox > * {
31+
background-color: #fff;
32+
border: none;
33+
display: inline-flex;
34+
align-items: center;
35+
justify-content: center;
36+
font-size: 2rem;
37+
height: 50px;
38+
width: 50px;
39+
margin: 0.25rem;
40+
padding: 0.25rem;
41+
cursor: pointer;
42+
}
43+
44+
.toolbox > *:last-child {
45+
margin-left: auto;
46+
}

0 commit comments

Comments
 (0)