Created
January 11, 2024 15:10
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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