HTML Canvas Paint App

Developer
Size
3,477 Kb
Views
10,120

How do I make an html canvas paint app?

What is a html canvas paint app? How do you make a html canvas paint app? This script and codes were developed by Adam on 28 November 2022, Monday.

HTML Canvas Paint App Previews

HTML Canvas Paint App - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>HTML Canvas Paint App</title> <link href="https://fonts.googleapis.com/css?family=Merienda+One" rel="stylesheet"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css"> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div class="container"> <div class="picture-frame"> <canvas></canvas> </div> <div class="controls"> <div> <label for="color">Colour:</label> <input class="color" type="color" name="color" value="#000000"></input> </div> <div> <label for="width">Line-Width:</label> <input class="line-width" type="range" name="width" min="1" max="50" value="10"></input> </div> <div> <label for="bg">Background:</label> <input class="bg" type="color" name="bg" value="#FFFFFF"></input> </div> <div> <button class="clear" name="clear">Clear</button> </div> </div>
</div> <script src="js/index.js"></script>
</body>
</html>

HTML Canvas Paint App - Script Codes CSS Codes

.color,
.bg, .clear { width: 100px; cursor: pointer; border: none;
}
.container, .picture-frame { display: flex; justify-content: center; align-items: center;
}
html { font-family: 'Merienda One', cursive; font-size: 24px; color: #333333; text-align: center;
}
body { background-color: #f9fca6;
}
.container { width: 600px; height: 600px; margin-top: 50px; flex-direction: column; margin: 0 auto;
}
.picture-frame { background-color: #333333; width: 100%; height: 50%; border: solid 40px #63380d; border-right-color: #4c2b0a; border-left-color: #7a4510; border-radius: 5px; box-shadow: 12px 12px 10px #222222;
}
canvas { background: white; border-radius: 5px; box-shadow: 5px 5px 10px #222222; cursor: crosshair; width: 90%; height: 85%;
}
.controls { margin: 20px 0 0; width: 100%; display: flex; justify-content: space-between;
}
.color,
.bg { height: 30px; background: none; padding: 10px 0 0 5px;
}
.line-width { border-radius: 5px; cursor: pointer;
}
.clear { background: #333333; color: white; font-family: 'Merienda One', cursive; font-size: 1rem; padding: 5px; border-radius: 10px;
}

HTML Canvas Paint App - Script Codes JS Codes

/*Paint style app using HTML5 Canvas and plain Javascript*/
//Build canvas
const canvas = document.querySelector('canvas');
const ctx = canvas.getContext('2d');
const p = document.querySelector('.picture-frame');
//Set canvas dimensions and drawing styles
canvas.width = 540;
canvas.height = 260;
ctx.lineCap = "round";
ctx.lineJoin = "round";
ctx.strokeStyle = "#000000";
ctx.lineWidth = 10;
//Element Selectors
const colorInput = document.querySelector(".color");
const widthInput = document.querySelector(".line-width");
const bgInput = document.querySelector(".bg");
const clearInput = document.querySelector(".clear");
//Functions to update style from user input
function colorUpdate(){ ctx.strokeStyle = this.value;
}
function widthUpdate(){ ctx.lineWidth = this.value;
}
function background(){ console.log(canvas); canvas.style.background = this.value;
}
function clearCanvas(){ ctx.clearRect(0, 0, canvas.width, canvas.height); canvas.style.background = "#FFFFFF"; bgInput.value = "#FFFFFF";
}
//User Input event listeners
colorInput.addEventListener('change', colorUpdate);
widthInput.addEventListener('change', widthUpdate);
bgInput.addEventListener('change', background);
clearInput.addEventListener('click', clearCanvas);
// draw function to draw on mousedown
let prevX = 0;
let prevY = 0;
let drawing = false;
function draw(e){ if(!drawing){ return; } ctx.beginPath(); ctx.moveTo(prevX, prevY); ctx.lineTo(e.offsetX, e.offsetY); ctx.stroke(); prevX = e.offsetX; prevY = e.offsetY;
}
//User drawing event listners
canvas.addEventListener('mousemove', draw);
canvas.addEventListener('mouseout', function(){drawing = false;});
canvas.addEventListener('mouseup', function(){drawing = false;});
canvas.addEventListener('mousedown', function(e){ drawing = true; prevX = e.offsetX; prevY = e.offsetY;
});
HTML Canvas Paint App - Script Codes
HTML Canvas Paint App - Script Codes
Home Page Home
Developer Adam
Username rzencoder
Uploaded November 28, 2022
Rating 3
Size 3,477 Kb
Views 10,120
Do you need developer help for HTML Canvas Paint App?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Adam (rzencoder) Script Codes
Create amazing sales emails with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!