Skip to content

Commit 936811f

Browse files
committed
Add size control for drawing and eraser tools
1 parent a581417 commit 936811f

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

notes.html

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,17 @@
121121
.color-picker {
122122
margin-left: 10px;
123123
}
124+
125+
.tool-settings {
126+
display: flex;
127+
align-items: center;
128+
gap: 10px;
129+
}
130+
131+
.size-slider {
132+
width: 100px;
133+
margin: 0 10px;
134+
}
124135
</style>
125136
</head>
126137
<body>
@@ -140,6 +151,9 @@ <h2>Your Notes</h2>
140151
<button class="tool-button" onclick="switchMode('draw')">Draw Mode</button>
141152
<button class="tool-button" onclick="setTool('pen')">Pen</button>
142153
<button class="tool-button" onclick="setTool('eraser')">Eraser</button>
154+
<div class="tool-settings">
155+
<label>Size: <input type="range" min="1" max="50" value="2" class="size-slider" onchange="setSize(this.value)"></label>
156+
</div>
143157
<input type="color" class="color-picker" onchange="setColor(this.value)" value="#000000">
144158
</div>
145159
<textarea id="notes" placeholder="Write your notes here..."></textarea>
@@ -157,6 +171,7 @@ <h2>Your Notes</h2>
157171
let isDrawing = false;
158172
let currentTool = 'pen';
159173
let currentColor = '#000000';
174+
let currentSize = 2;
160175
const canvas = document.getElementById('canvas');
161176
const ctx = canvas.getContext('2d');
162177
const textarea = document.getElementById('notes');
@@ -203,6 +218,10 @@ <h2>Your Notes</h2>
203218
currentColor = color;
204219
}
205220

221+
function setSize(size) {
222+
currentSize = parseInt(size);
223+
}
224+
206225
canvas.addEventListener('mousedown', startDrawing);
207226
canvas.addEventListener('mousemove', draw);
208227
canvas.addEventListener('mouseup', stopDrawing);
@@ -220,12 +239,11 @@ <h2>Your Notes</h2>
220239
const x = e.clientX - rect.left;
221240
const y = e.clientY - rect.top;
222241

223-
ctx.lineWidth = 2;
242+
ctx.lineWidth = currentTool === 'eraser' ? currentSize * 2 : currentSize;
224243
ctx.lineCap = 'round';
225244

226245
if (currentTool === 'eraser') {
227246
ctx.strokeStyle = '#ffffff';
228-
ctx.lineWidth = 20;
229247
} else {
230248
ctx.strokeStyle = currentColor;
231249
}

0 commit comments

Comments
 (0)