Write a Paint-like app in HTML, CSS, and JS, make it dark mode with a sleek design, only…
- User
Write a Paint-like app in HTML, CSS, and JS, make it dark mode with a sleek design, only the canvas I'm gonna draw at should be white...
- Assistant
Write a Paint-like app in HTML, CSS, and JS, make it dark mode with a sleek design, only the canvas I'm gonna draw at should be white...
Creating a Paint-like application with a sleek dark mode design involves setting up an HTML structure, styling it with CSS, and adding interactivity using JavaScript. Below is a complete example that you can use. The application includes a toolbar with options to select brush color and size, an eraser, and a clear canvas button. The canvas area is white, contrasting against the dark mode UI.
Create an index.html file and add the following content:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dark Mode Paint App</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="toolbar">
<button id="pen" class="tool active">Pen</button>
<button id="eraser" class="tool">Eraser</button>
<input type="color" id="colorPicker" value="#ffffff">
<input type="range" id="brushSize" min="1" max="50" value="5">
<button id="clear">Clear</button>
</div>
<div class="canvas-container">
<canvas id="canvas"></canvas>
</div>
<script src="script.js"></script>
</body>
</html>
Create a styles.css file and add the following styles:
/* Reset default browser styles */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
background-color: #121212;
color: #ffffff;
font-family: Arial, sans-serif;
height: 100vh;
display: flex;
flex-direction: column;
}
/* Toolbar styling */
.toolbar {
display: flex;
align-items: center;
padding: 10px;
background-color: #1e1e1e;
border-bottom: 1px solid #333;
}
.toolbar .tool {
background-color: #2c2c2c;
border: none;
color: #fff;
padding: 8px 12px;
margin-right: 10px;
cursor: pointer;
border-radius: 4px;
transition: background-color 0.3s;
}
.toolbar .tool:hover,
.toolbar .tool.active {
background-color: #3c3c3c;
}
.toolbar input[type="color"] {
margin-right: 10px;
cursor: pointer;
border: none;
padding: 0;
width: 40px;
height: 40px;
}
.toolbar input[type="range"] {
margin-right: 10px;
}
/* Canvas styling */
.canvas-container {
flex: 1;
display: flex;
justify-content: center;
align-items: center;
padding: 20px;
}
#canvas {
border: 2px solid #333;
background-color: #ffffff;
border-radius: 4px;
/* Make the canvas responsive */
width: 100%;
max-width: 800px;
height: 600px;
cursor: crosshair;
}
Create a script.js file and add the following script:
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
const penButton = document.getElementById('pen');
const eraserButton = document.getElementById('eraser');
const colorPicker = document.getElementById('colorPicker');
const brushSize = document.getElementById('brushSize');
const clearButton = document.getElementById('clear');
let isDrawing = false;
let currentTool = 'pen';
let currentColor = '#000000';
let currentSize = 5;
// Set canvas size
function resizeCanvas() {
canvas.width = canvas.offsetWidth;
canvas.height = canvas.offsetHeight;
}
window.addEventListener('resize', resizeCanvas);
resizeCanvas();
// Start drawing
canvas.addEventListener('mousedown', (e) => {
isDrawing = true;
ctx.beginPath();
ctx.moveTo(e.offsetX, e.offsetY);
});
// Draw
canvas.addEventListener('mousemove', (e) => {
if (isDrawing) {
ctx.lineWidth = currentSize;
ctx.lineCap = 'round';
if (currentTool === 'eraser') {
ctx.strokeStyle = '#ffffff';
} else {
ctx.strokeStyle = currentColor;
}
ctx.lineTo(e.offsetX, e.offsetY);
ctx.stroke();
}
});
// Stop drawing
canvas.addEventListener('mouseup', () => {
isDrawing = false;
});
// Tool selection
penButton.addEventListener('click', () => {
currentTool = 'pen';
penButton.classList.add('active');
eraserButton.classList.remove('active');
});
eraserButton.addEventListener('click', () => {
currentTool = 'eraser';
eraserButton.classList.add('active');
penButton.classList.remove('active');
});
// Color picker
colorPicker.addEventListener('change', (e) => {
currentColor = e.target.value;
});
// Brush size
brushSize.addEventListener('input', (e) => {
currentSize = e.target.value;
});
// Clear canvas
clearButton.addEventListener('click', () => {
ctx.clearRect(0, 0, canvas.width, canvas.height);
});
HTML: Sets up the structure with a toolbar containing tools like pen, eraser, color picker, brush size slider, and a clear button. The canvas is placed inside a container that centers it on the page.
CSS:
JavaScript:
Setup: Create a project folder and add three files: index.html, styles.css, and script.js with the respective code provided above.
Run: Open index.html in your web browser.
Draw:
To make the application more feature-rich, consider adding the following:
Here's how you can add a save functionality:
HTML: Add a save button to the toolbar.
<button id="save">Save</button>
CSS: Style the save button similarly to other toolbar buttons.
/* Add within .toolbar styles */
#save {
background-color: #2c2c2c;
border: none;
color: #fff;
padding: 8px 12px;
margin-right: 10px;
cursor: pointer;
border-radius: 4px;
transition: background-color 0.3s;
}
#save:hover {
background-color: #3c3c3c;
}
JavaScript: Implement the save functionality.
const saveButton = document.getElementById('save');
saveButton.addEventListener('click', () => {
const link = document.createElement('a');
link.download = 'drawing.png';
link.href = canvas.toDataURL();
link.click();
});
This example provides a foundational Paint-like application with a dark mode interface and a white canvas for drawing. You can expand upon this by adding more features and improving the UI/UX based on your requirements.
Feel free to customize the styles and functionalities to better suit your preferences!
Not yet included in a published release.