Lerp and Dotted Lines

Hi! I'm new to p5.js and want to know how I can draw a dotted line. I saw in the documentation that method lerp can be used for drawing dotted line. Did anyone know how I can do that.

Answers

  • On the processing reference there is an example of dotted line created using lerp https://processing.org/reference/lerp_.html

    function setup() {
      var x1 = 15;
      var y1 = 10;
      var x2 = 80;
      var y2 = 90;
    
      line(x1, y1, x2, y2);
    
      for (var i = 0; i <= 10; i++) {
        var x = lerp(x1, x2, i/10.0) + 10;
        var y = lerp(y1, y2, i/10.0);
    
        point(x, y);
      }
    }
    
Sign In or Register to comment.