This is a reusable p5.js function for drawing standard Causal Loop Diagram (CLD) notation symbols — a circular arrow with an "R" (reinforcing) or "B" (balancing) label in the center. Supports both clockwise and counter-clockwise directions. Developed during the feedback-loop-explorer MicroSim build on 2026-03-30.
Usage
1
drawLoopIndicator(cx,cy,r,col,label,dc)
Parameter
Description
cx, cy
Center coordinates of the symbol
r
Radius of the circular arrow (18 works well)
col
p5.js color for the arrow and label
label
'R' for reinforcing or 'B' for balancing
dc
Direction code: 'CW' for clockwise (default), 'CCW' for counter-clockwise
functiondrawLoopIndicator(cx,cy,r,col,label,dc){// Draw a circular arrow around a CLD loop label// dc: 'CW' for clockwise (default), 'CCW' for counter-clockwiseif(!dc)dc='CW';letccw=(dc==='CCW');letgapAngle=PI/3;// 60-degree gap at top// CW: arc runs in positive direction; CCW: arc runs in negative directionletstartA,endA;if(ccw){startA=-PI/2-gapAngle/2;endA=startA-(TWO_PI-gapAngle);}else{startA=-PI/2+gapAngle/2;endA=startA+(TWO_PI-gapAngle);}noFill();stroke(col);strokeWeight(2);letsteps=40;beginShape();for(leti=0;i<=steps;i++){leta=startA+(i/steps)*(endA-startA);vertex(cx+cos(a)*r,cy+sin(a)*r);}endShape();// Arrowhead at end of arclettipAngle=endA;lettipX=cx+cos(tipAngle)*r;lettipY=cy+sin(tipAngle)*r;// Tangent along arc direction, with 15 degree adjustment for visual centeringlettangent;if(ccw){tangent=tipAngle-PI/2+PI/12;}else{tangent=tipAngle+PI/2-PI/12;}fill(col);noStroke();push();translate(tipX,tipY);rotate(tangent);triangle(0,0,-10,-4,-10,4);pop();// Label text centered inside the arcfill(col);noStroke();textSize(18);textAlign(CENTER,CENTER);text(label,cx,cy+1);}
Design Notes
The arc gap is 60 degrees at the top, giving the arrowhead room
The arrowhead tangent is rotated 15 degrees from the true tangent for better visual centering on the arc
The arrow tip sits exactly on the arc path
dc parameter defaults to 'CW' if omitted, so existing calls without it are unaffected