Glad you asked ;) Here's an example of the upcoming toxiclibs 0021 release which will support dashing of arbitrary line strips (including arcs/splines etc.). This example also works with the current release, but the code can be simplified in future:
- import toxi.geom.*;
- import toxi.processing.*;
- ToxiclibsSupport gfx;
- void setup() {
- size(400,400);
- smooth();
- gfx=new ToxiclibsSupport(this);
- }
- void draw() {
- background(255);
- noFill();
- // stroked arc with resolution of 10 segments
- gfx.lineStrip2D(createArc(200,200,0,PI,80,10));
- // dotted arc with res=20
- gfx.points2D(createArc(200,200,PI,PI*1.5,100,20));
- // dashed arc with res=10
- // only every 2nd segment will be drawn
- // (will be part of toxiclibs 0021)
- Vec2D prev=null;
- boolean doDash=false;
- for(Vec2D p : createArc(200,200,PI*1.5,TWO_PI,120,10)) {
- if (prev!=null && doDash) {
- gfx.line(prev,p);
- }
- prev=p;
- doDash=!doDash;
- }
- }
- /**
- * Computes a list of vertices on the arc between a -> b (in radians).
- * Has support for different resolutions.
- *
- * @param a start angle
- * @param b end angle (inclusive)
- * @param radius
- * @param res number of segments
- */
- List<Vec2D> createArc(float x, float y, float a, float b, float radius, int res) {
- List<Vec2D> points=new ArrayList<Vec2D>();
- for(float theta=a, delta=(b-a)/res; theta<b; theta+=delta) {
- Vec2D p=new Vec2D(radius,theta).toCartesian().addSelf(x,y);
- points.add(p);
- }
- points.add(new Vec2D(radius,b).toCartesian().addSelf(x,y));
- return points;
- }
Hth!