• fullscreen
  • sketch28215.pde
  • float radius = 50;
    
    void setup() {
        size(200, 200);
        noFill();
        stroke(0);
    }
    
    void draw() {
        background(255);
        
        translate(100, 100);
        dashedCircle(50, 6, 4);
    }
    
    void dashedCircle(float radius, int dashWidth, int dashSpacing) {
        int steps = 200;
        int dashPeriod = dashWidth + dashSpacing;
        boolean lastDashed = false;
        for(int i = 0; i < steps; i++) {
          boolean curDashed = (i % dashPeriod) < dashWidth;
          if(curDashed && !lastDashed) {
            beginShape();
          }
          if(!curDashed && lastDashed) {
            endShape();
          }
          if(curDashed) {
            float theta = map(i, 0, steps, 0, TWO_PI);
            vertex(cos(theta) * radius, sin(theta) * radius);
          }
          lastDashed = curDashed;
        }
        if(lastDashed) {
          endShape();
        }
    }

    code

    tweaks (0)

    about this sketch

    This sketch is running in HTML5 using Processingjs.

    license

    advertisement

    Kyle McDonald

    Dashed Circle

    Add to Faves Me Likey@! 4
    You must login/register to add this sketch to your favorites.

    Simple function for drawing a dashed circle.

    Charles Carr
    3 Feb 2012
    Your stuff is all very clever! :)
    You need to login/register to comment.