Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PVector[] p; // array of points
- float[] dists; // array of distances between consecutive points
- float[] frac; // array of fraction of total distance (normalized to TWO_PI)
- float totalDist; // total distance covered by dists
- int n = 3; // n-pointed star
- int N = n*20; // number of circles
- int r = 5; // circle radius
- float R = .8; // star radius
- float time = 0;
- float step = PI/420; // increase time by step every iteration
- void setup() {
- size(500, 500);
- p = new PVector[n];
- int k = 0;
- for (int i=0; i<n; i++) {
- float x = R*cos(TWO_PI*k/n);
- float y = R*sin(TWO_PI*k/n);
- p[i] = new PVector(x, y);
- k = (k-1)%n;
- }
- dists = new float[n];
- frac = new float[n];
- totalDist = 0;
- PVector pprev;
- PVector pnext;
- for (int i=0; i<n; i++) {
- pprev = p[i];
- if (i == n-1) {
- pnext = p[0];
- } else {
- pnext = p[i+1];
- }
- float d = dist(pprev.x, pprev.y, pnext.x, pnext.y);
- totalDist += d;
- dists[i] = d;
- }
- for (int i=0; i<n; i++) {
- frac[i] = dists[i]/totalDist * TWO_PI;
- }
- fill(255);
- noStroke();
- background(0);
- }
- void draw() {
- fill(0, 10);
- rect(0, 0, width, height);
- translate(width/2, height/2);
- rotate(time);
- fill(0, 255, 255);
- for (int k=0; k<N; k++) {
- float t = (time + TWO_PI/N*k) % TWO_PI;
- float ftotal = 0;
- for (int i=0; i<n; i++) {
- float f = frac[i];
- ftotal += f;
- if (t <= ftotal) {
- float fdir = (f-(ftotal-t))/f;
- PVector start = PVector.mult(p[i], width/2);
- PVector end = PVector.mult(p[(i+1)%n], width/2);
- PVector direction = PVector.sub(end, start);
- PVector pos = PVector.add(start, PVector.mult(direction, fdir));
- circle(pos.x, pos.y, r);
- break;
- }
- }
- }
- time += step;
- }
Advertisement
Add Comment
Please, Sign In to add comment