Drawing App
About this app
A fun drawing app where you can create and erase drawings.
Drawing App Clear Reset Color
Related apps
Put this on your site
Source
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Drawing App</title>
<meta name="description" content="A fun drawing app where you can create and erase drawings.">
<meta name="keywords" content="drawing, app, paint, colors, creativity">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/5.0.2/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Quicksand:400,700&display=swap" rel="stylesheet">
<script type="text/javascript">
try {
// App Javascript Goes Here. Place your entire script content inside the try block for error handling.
document.addEventListener("DOMContentLoaded", function() {
// Canvas variables
var canvas = document.getElementById("drawing-canvas");
var context = canvas.getContext("2d");
// Drawing variables
var isDrawing = false;
var lastX = 0;
var lastY = 0;
// Event listeners
canvas.addEventListener("mousedown", startDrawing);
canvas.addEventListener("mousemove", draw);
canvas.addEventListener("mouseup", stopDrawing);
canvas.addEventListener("mouseout", stopDrawing);
// Start drawing function
function startDrawing(e) {
isDrawing = true;
lastX = e.offsetX;
lastY = e.offsetY;
}
// Draw function
function draw(e) {
if (!isDrawing) return;
context.beginPath();
context.moveTo(lastX, lastY);
context.lineTo(e.offsetX, e.offsetY);
context.stroke();
lastX = e.offsetX;
lastY = e.offsetY;
}
// Stop drawing function
function stopDrawing() {
isDrawing = false;
}
// Clear canvas function
function clearCanvas() {
context.clearRect(0, 0, canvas.width, canvas.height);
}
// Change color function
function changeColor(color) {
context.strokeStyle = color;
}
// Reset color function
function resetColor() {
context.strokeStyle = "#000000";
}
});
} catch (error) {
// This will throw the error to the parent window.
throw error;
}
</script>
<style>
body {
font-family: 'Quicksand', sans-serif;
background-color: #f5f5f5;
}
#main-container {
text-align: center;
margin-top: 50px;
}
#drawing-canvas {
border: 1px solid #ccc;
background-color: #ffffff;
cursor: crosshair;
}
.btn-group {
margin-bottom: 20px;
}
.btn-group .btn {
margin-right: 10px;
}
.color-selector {
display: inline-block;
width: 30px;
height: 30px;
border-radius: 50%;
cursor: pointer;
}
.color-selector:hover {
border: 2px solid #000000;
}
</style>
</head>
<body>
<div id="main-container" class="container">
<div class="btn-group">
<button class="btn btn-primary" onclick="clearCanvas()"><i class="fa fa-trash"></i> Clear</button>
<button class="btn btn-primary" onclick="resetColor()"><i class="fa fa-paint-brush"></i> Reset Color</button>
</div>
<canvas id="drawing-canvas" width="500" height="500"></canvas>
<div class="btn-group">
<div class="color-selector" style="background-color: #000000" onclick="changeColor('#000000')"></div>
<div class="color-selector" style="background-color: #ff0000" onclick="changeColor('#ff0000')"></div>
<div class="color-selector" style="background-color: #00ff00" onclick="changeColor('#00ff00')"></div>
<div class="color-selector" style="background-color: #0000ff" onclick="changeColor('#0000ff')"></div>
</div>
</div>
</body>
</html>
NEW APPS
These are apps made by the community!