Skip to content

Instantly share code, notes, and snippets.

@SpineyPete
Created December 4, 2018 19:35
Show Gist options
  • Save SpineyPete/0f2ae2bbfe7a222f01158c14a6279890 to your computer and use it in GitHub Desktop.
Save SpineyPete/0f2ae2bbfe7a222f01158c14a6279890 to your computer and use it in GitHub Desktop.
Adaptively Subdivided Fan (Processing 3.0)
PVector clickPos = new PVector(0, 0);
PVector clickRadi = new PVector(100, 100);
void angler(
PVector arcPos, float arcRadi, float arcTurn, PVector arcDir,
float stepSize, boolean fixStep) {
float halfAngle = PI*arcTurn;
float totalAngle = TAU*arcTurn;
float totalSteps = totalAngle*arcRadi/stepSize;
float angleStep = totalAngle/round(totalSteps);
float dirAngle = atan2(arcPos.x - arcDir.x, arcPos.y - arcDir.y);
if (fixStep) {
dirAngle = dirAngle - (dirAngle % angleStep); // move in increments
}
for (float angle = -halfAngle; angle < halfAngle; angle += angleStep) {
float a = PI + angle + dirAngle; // pi to point towards arcDir
float x0 = arcPos.x + sin(a)*arcRadi;
float y0 = arcPos.y + cos(a)*arcRadi;
line(arcPos.x, arcPos.y, x0, y0);
ellipse(x0, y0, 5, 5);
}
};
void setup() {
size(600, 600, FX2D);
// noLoop();
};
void draw() {
if (mousePressed) {
clickPos.x = mouseX;
clickPos.y = mouseY;
clickRadi.x = width/2 - clickPos.x;
clickRadi.y = height/2 - clickPos.y;
}
background(255);
fill(0, 0, 0);
angler(
new PVector(width/2, height/2),
clickRadi.mag(), 0.2,
clickPos,
30, true);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment