Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <meta http-equiv="X-UA-Compatible" content="ie=edge">
- <title>Document</title>
- <link rel="stylesheet" type="text/css" href="draw.css">
- </head>
- <body>
- <input type="range" min="1" max="" value="10" onchange="changeLine(this.value)">
- <canvas id="canvas"></canvas>
- <script>
- function changeLine(val){
- lineWidth = val;
- }
- var lineWidth = 10;
- window.addEventListener("load",()=>{
- const canvas = document.querySelector("canvas")
- const ctx = canvas.getContext("2d")
- canvas.height = innerHeight;
- canvas.width = innerWidth;
- let painting = false;
- function startPosition(e){
- painting = true;
- draw(e)
- }
- function finishedPosition(){
- painting = false
- ctx.beginPath();
- }
- function draw(e){
- if(!painting) return;
- ctx.lineWidth = lineWidth;
- ctx.lineCap = "round";
- ctx.lineTo(e.clientX,e.clientY)
- ctx.stroke();
- ctx.beginPath();
- ctx.moveTo(e.clientX,e.clientY)
- }
- canvas.addEventListener("mousedown", startPosition);
- canvas.addEventListener("mouseup", finishedPosition);
- canvas.addEventListener("mousemove", draw);
- });
- window.addEventListener("resize", ()=>{
- canvas.height = innerHeight;
- canvas.width = innerWidth;
- });
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement