Skip to content

Instantly share code, notes, and snippets.

@KrabCode
Created January 11, 2024 15:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KrabCode/8e5cd8b09195de4f5df187d3411866f7 to your computer and use it in GitHub Desktop.
Save KrabCode/8e5cd8b09195de4f5df187d3411866f7 to your computer and use it in GitHub Desktop.
Rotating concentric lines. Original solution to the dashed circle problem is by nking.
void setup() {
size(640, 640, P2D);
smooth(8);
strokeCap(SQUARE);
}
void draw() {
background(100);
translate(width/2, height/2);
float startingRadius = 60;
float dashLength = 50;
float startingDashCount = 6;
float dashCountIncrement = 5;
int circleCount = 5;
float startingAngle = TWO_PI / startingDashCount;
// the arc length between the beginnings of two dashes
float startingArcLength = startingAngle * startingRadius;
float incrementedAngle = TWO_PI / (startingDashCount + dashCountIncrement);
// we want to keep the arc length the same,
// so we calculate the radius to fit the required amount of arc lengths
float incrementedRadius = startingArcLength / incrementedAngle;
float radiusIncrement = incrementedRadius - startingRadius;
float t = radians(frameCount) * 0.35;
fill(0);
noStroke();
circle(0, 0, startingRadius * 2);
for (int i = 0; i < circleCount; i++) {
pushMatrix();
float rotationSign = 1;
if(i % 2 == 0){
rotationSign = -1;
}
rotate(rotationSign * t * (circleCount - i));
noFill();
stroke(0);
strokeWeight(radiusIncrement + 4);
float currentRadius = startingRadius + radiusIncrement * i;
float currentDiameter = currentRadius * 2;
circle(0, 0, currentDiameter);
// drawing the dashes for the current circle
stroke(255);
strokeWeight(radiusIncrement / 3);
float currentDashCount = startingDashCount + dashCountIncrement * i;
for (int j = 0; j < currentDashCount; j++) {
float dashAngle = dashLength / currentRadius;
float angleOffset = -dashAngle / 2;
if (i % 2 == 1) {
// rotate every other dashed circle by 45 degrees
angleOffset += QUARTER_PI;
}
float arcAngle = TWO_PI / currentDashCount;
float arcStartAngle = angleOffset + arcAngle * j;
float arcEndAngle = arcStartAngle + dashAngle;
arc(0, 0, currentDiameter, currentDiameter, arcStartAngle, arcEndAngle);
}
popMatrix();
}
/*
if (frameCount < 500) {
save("rec6/" + frameCount + ".jpg");
}
*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment