Skip to content
TheChatArchiveThe Chat Archive
Coherecommand-a-03-2025· CohereHugging Face LMArena Human Preference 140K

Create a clone of excalidraw.com in HTML, make no mistakes

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Claudeclaude-3-7-sonnet-20250219’s answer.
  1. User

    Create a clone of excalidraw.com in HTML, make no mistakes

  2. Cohere Assistant

    Creating a clone of Excalidraw.com in HTML, CSS, and JavaScript is a complex task, but I'll provide you with a simplified version that captures the core functionality. This example will include a basic drawing canvas, tools for drawing, and a sidebar for selecting tools. Note that this is a simplified clone and does not include all features of Excalidraw, such as collaboration, advanced shapes, or exporting.

    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>Excalidraw Clone</title>
      <style>
        body {
          margin: 0;
          font-family: Arial, sans-serif;
          display: flex;
          height: 100vh;
          overflow: hidden;
        }
        .sidebar {
          width: 50px;
          background-color: #f0f0f0;
          display: flex;
          flex-direction: column;
          align-items: center;
          padding: 10px;
          gap: 10px;
        }
        .sidebar button {
          background: none;
          border: none;
          cursor: pointer;
          font-size: 20px;
          padding: 5px;
        }
        .canvas-container {
          flex: 1;
          background-color: #fff;
          position: relative;
        }
        canvas {
          border: 1px solid #ccc;
          cursor: crosshair;
        }
      </style>
    </head>
    <body>
      <div class="sidebar">
        <button id="penTool" title="Pen Tool">✏️</button>
        <button id="eraserTool" title="Eraser Tool">🧹</button>
        <button id="clearCanvas" title="Clear Canvas">🗑️</button>
      </div>
      <div class="canvas-container">
        <canvas id="drawingCanvas"></canvas>
      </div>
    
      <script>
        const canvas = document.getElementById('drawingCanvas');
        const ctx = canvas.getContext('2d');
        const penTool = document.getElementById('penTool');
        const eraserTool = document.getElementById('eraserTool');
        const clearCanvasBtn = document.getElementById('clearCanvas');
    
        // Set canvas size to fit the container
        const resizeCanvas = () => {
          canvas.width = window.innerWidth - 70; // Adjust for sidebar width
          canvas.height = window.innerHeight;
        };
        window.addEventListener('resize', resizeCanvas);
        resizeCanvas();
    
        let isDrawing = false;
        let currentTool = 'pen';
        let eraserSize = 20;
    
        const startDrawing = (e) => {
          isDrawing = true;
          draw(e);
        };
    
        const stopDrawing = () => {
          isDrawing = false;
          ctx.beginPath();
        };
    
        const draw = (e) => {
          if (!isDrawing) return;
          const rect = canvas.getBoundingClientRect();
          const x = e.clientX - rect.left;
          const y = e.clientY - rect.top;
    
          if (currentTool === 'pen') {
            ctx.lineWidth = 2;
            ctx.lineCap = 'round';
            ctx.strokeStyle = '#000';
            ctx.lineTo(x, y);
            ctx.stroke();
            ctx.beginPath();
            ctx.moveTo(x, y);
          } else if (currentTool === 'eraser') {
            ctx.clearRect(x - eraserSize / 2, y - eraserSize / 2, eraserSize, eraserSize);
          }
        };
    
        penTool.addEventListener('click', () => {
          currentTool = 'pen';
        });
    
        eraserTool.addEventListener('click', () => {
          currentTool = 'eraser';
        });
    
        clearCanvasBtn.addEventListener('click', () => {
          ctx.clearRect(0, 0, canvas.width, canvas.height);
        });
    
        canvas.addEventListener('mousedown', startDrawing);
        canvas.addEventListener('mouseup', stopDrawing);
        canvas.addEventListener('mousemove', draw);
        canvas.addEventListener('mouseout', stopDrawing);
      </script>
    </body>
    </html>
    

    Features Included:

    1. Canvas: A resizable canvas that fills the screen.
    2. Tools:
      • Pen Tool (✏️): Draws freehand lines.
      • Eraser Tool (🧹): Erases parts of the drawing.
      • Clear Canvas (🗑️): Clears the entire canvas.
    3. Responsive Design: The canvas adjusts to the window size.

    How to Use:

    1. Open the HTML file in a browser.
    2. Use the sidebar tools to draw or erase.
    3. Resize the window to see the canvas adjust dynamically.

    Limitations:

    • No advanced shapes (e.g., rectangles, arrows).
    • No collaboration features.
    • No exporting functionality.
    • Simplified eraser tool (fixed size).

    This is a basic implementation. For a full-featured clone like Excalidraw, you would need to incorporate advanced libraries (e.g., Fabric.js, Konva.js) and additional JavaScript logic for handling shapes, text, and collaboration.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.