HTML Canvas Paint App
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 - 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;
});
Developer | Adam |
Username | rzencoder |
Uploaded | November 28, 2022 |
Rating | 3 |
Size | 3,477 Kb |
Views | 10,120 |
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!
Name | Size |
Placeholder Portfolio | 7,180 Kb |
React Game of Life | 7,264 Kb |
Random Movie Quote Generator | 3,861 Kb |
Scatterplot Graph D3 | 5,762 Kb |
Markdown Previewer | 3,929 Kb |
Heat Map Data Visualisation D3 | 5,591 Kb |
React Betting App | 6,005 Kb |
Scrolling Effects Practice | 6,441 Kb |
Countdown Anagram Game | 7,625 Kb |
React Leaderboard | 4,333 Kb |
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!
Name | Username | Size |
A Pen by Jess | Jessamyne | 5,100 Kb |
Text Looping Transition | Agelber | 5,619 Kb |
Classy Blockquote Styling | Andrewwright | 3,212 Kb |
Print element on a page | Mrs_snow | 2,081 Kb |
Day 11 - Calendar Card | Arnellebalane | 6,984 Kb |
CSS eye follow | Pedrocampos | 2,592 Kb |
Ionic Infinite outside ion-content with ion-pane | Felquis | 3,117 Kb |
Mobile first social buttons with no iframe | Alistairtweedie | 3,158 Kb |
Bubble animation | Ftabor | 6,565 Kb |
Stylize Stories | Jvhti | 2,465 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!