CS 151 - Day 18

Cover page image

Cay S. Horstmann

Lab

lab

Canvas

  1. Continue with your graphed.html, graphed.js, graphed.css from the previous lab. Or if you couldn't get the previous lab to work, use this, this, and this.
  2. Replace the SVG element with a Canvas element.
  3. In the draw method of the circle node, draw on the canvas instead of generating SVG.
    const canvas = ...
    const ctx = ... // No need for "if (canvas.getContext)"
    ctx.beginPath()
    ctx.arc(...)
    ctx.fillStyle = ...
    ctx.fill()
    
  4. Do the same in the drawGrabber function.
  5. Now you should be able to drag a node. What happens?
  6. What can you do to fix it? Hint:
    ctx.clearRect(0, 0, canvas.width, canvas.height)

Drawing Lines

Boxes and Arrows

HTML Boxes in graphed