Curve vertex contour problem

i not play with contour…

but for the

curveVertex

-a- must close the curve manually
( 4 corners are 5 curveVertex points where the last same the first )
and then not even need the CLOSE.

and as the reference says
need to define 2 add vertex points

control points

for the start angle
so actually you go 1.5 times around your shape ( 7 points )
and it works

use

let w = 40;

  function setup() {
    createCanvas(400, 400);
  }

  function draw() {
    translate(100, 100);
    w = 40;
    beginShape();
    curveVertex(-w, w);
    curveVertex(-w, -w);
    curveVertex(w, -w);
    curveVertex(w, w);
    curveVertex(-w, w);
    curveVertex(-w, -w);
    curveVertex(w, -w);
    endShape();
    w = 20;
    beginShape();
    curveVertex(-w, w);
    curveVertex(-w, -w);
    curveVertex(w, -w);
    curveVertex(w, w);
    curveVertex(-w, w);
    curveVertex(-w, -w);
    curveVertex(w, -w);
    endShape();
  }

more about control points