Shared Multi User Canvas Drawing with HTML and JavaScript

Stephen Blum · Beginner ·🖌️ UI/UX Design ·1d ago

Key Takeaways

Creates a shared multi-user canvas drawing app with HTML and JavaScript

Original Description

Today we keep building our shared bitmap drawing app. We start by sizing the canvas, using flexbox to lay things out, and adding a simple color picker. Instead of hard coding colors in JavaScript, we use data attributes in the HTML, then read them on click to set the canvas strokeStyle. Once colors work, we add real time multiplayer with PubNub by publishing each stroke as a message that includes the previous and current coordinates plus the selected color. On the receive side, we draw the same line using beginPath, moveTo, lineTo, and stroke, which makes it smooth instead of a trail of dots. After fixing a small coordinate mix up and confirming color sync, we test with two users and it works. Last, we add touchstart and touchmove so it also works on mobile, then commit and push the update.
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Related Reads

Up next
Designrr eBook Tutorial: How to Make a Book Cover Fast!
LoverFighterWriter
Watch →