100%
Radar (M)
Start sketching freely, or load a production-ready starter template:
Excalidraw does not implement its own hand-drawn jitter algorithm from scratch. Instead, it delegates all sketchy strokes and hachure fills to Rough.js (created by Preet Shihn).
// Excalidraw creates a RoughCanvas wrapper over native HTML5 Canvas
const roughCanvas = rough.canvas(canvas);
// Deterministic seed is stored ON THE ELEMENT to prevent shimmering/jittering across frames:
const shape = generator.rectangle(x, y, width, height, {
seed: element.seed, // e.g., 184920492
roughness: element.roughness, // 0 = architectural, 1 = hand-drawn, 2 = cartoon
stroke: element.strokeColor,
fill: element.backgroundColor,
fillStyle: element.fillStyle, // 'hachure' | 'cross-hatch' | 'solid' | 'dots'
strokeWidth: element.strokeWidth
});
roughCanvas.draw(shape);
seed is the most critical property:
If Rough.js were called with random numbers on every frame, every time you pan, zoom, or move your mouse, the jittered strokes would fluctuate wildly (like high-frequency static noise). By persisting an integer seed per element, the PRNG produces the exact same jittered path coordinates frame after frame.
Every shape in Excalidraw is a pure, serializable JavaScript object. In @excalidraw/element/types.ts:
interface ExcalidrawElement {
id: string; // Unique nanoid/uuid
type: "rectangle" | "diamond" | "ellipse" | "arrow" | "line" | "freedraw" | "text";
x: number; // World coordinate X
y: number; // World coordinate Y
width: number;
height: number;
angle: number; // Rotation in radians
strokeColor: string;
backgroundColor: string;
fillStyle: "hachure" | "cross-hatch" | "solid" | "dots";
strokeWidth: number;
strokeStyle: "solid" | "dashed" | "dotted";
roughness: number; // 0 to 2.5
opacity: number; // 0 to 100
seed: number; // Deterministic PRNG seed for Rough.js
points?: [number, number][]; // For lines, arrows, and freedraw
text?: string; // For text elements
fontSize?: number;
}
The canvas allows infinite panning and continuous pinch/wheel zooming. All mouse events occur in Screen Space, but all element positions must be stored in Scene (World) Space:
sceneX = (clientX - scrollX) / zoomsceneY = (clientY - scrollY) / zoom
ctx.save();ctx.translate(scrollX, scrollY);ctx.scale(zoom, zoom);// Now draw all elements in their native scene coordinates!ctx.restore();
Adjust parameters below to see how Rough.js creates the signature sketchy hand-drawn feel in real time:
flowchart TD, sequenceDiagram, or graph LR):
Are you sure you want to clear the entire canvas? All current elements will be removed. You can press Ctrl+Z to undo if needed.