Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int numAnchors = 7; // numbers of anchor points
- int n=5; // number of subdivisions
- int frames = 100;
- int exp = int(pow(2, n));
- int dir;
- float theta, fc;
- boolean save;
- Curve[] myCurves = new Curve[numAnchors];
- PVector[] origAnchors = new PVector[numAnchors];
- PVector[] myAnchors = new PVector[numAnchors];
- void setup() {
- size(750, 500, P2D);
- smooth(8);
- background(20);
- generateAnchors();
- updateAnchors();
- generateBlob();
- }
- void draw() {
- updateAnchors();
- generateBlob();
- if (save) {
- if (frameCount<=fc+frames) saveFrame("image-###.gif");
- }
- theta += TWO_PI/frames;
- }
- void generateAnchors() {
- for (int i=0; i<numAnchors; i++) {
- float r = 25;
- float d = 200+i*random(-r, r);
- float vx = width/2 + cos(TWO_PI/numAnchors*i)*d;
- float vy = height/2 + sin(TWO_PI/numAnchors*i)*d;
- origAnchors[i] = new PVector(vx, vy);
- myAnchors[i] = origAnchors[i].get();
- }
- }
- void updateAnchors() {
- for (int i=0; i<numAnchors; i++) {
- dir=i%2==0?1:-1;
- myAnchors[i].x = origAnchors[i].x + cos(theta)*(i+1)*10*dir;
- myAnchors[i].y = origAnchors[i].y + sin(theta)*(i+1)*10*dir;
- }
- }
- void generateBlob() {
- background(0);
- fill(255);
- beginShape();
- for (int i=0; i<numAnchors; i++) {
- myCurves[i] = new Curve(myAnchors[(i+1)%numAnchors], myAnchors[(i+2)%numAnchors], myAnchors[i%numAnchors]);
- myCurves[i].generateRatios();
- myCurves[i].createVertices();
- }
- endShape(CLOSE);
- }
- void mouseReleased() {
- generateAnchors();
- generateBlob();
- }
- void keyPressed() {
- fc = frameCount;
- save = true;
- }
- void generateRatios() {
- float denom = pow(4, n);
- for (int i=0; i<(exp/2); i++) {
- ratioB[i] = (((i*(i+1))/2.0))/denom;
- ratioC[i] = ((((exp-i-1)*(exp-i))/2.0))/denom;
- ratioA[i] = 1-ratioB[i]-ratioC[i];
- }
- for (int i=exp/2; i<exp; i++) {
- ratioB[i] = ((i*(i+1))/2)/denom;
- ratioC[i] = (((exp-i-1)*(exp-i))/2)/denom;
- ratioA[i] = 1-ratioB[i]-ratioC[i];
- }
- }
- void createVertices() {
- for (int i=0; i<exp; i++) {
- float px = A.x*ratioA[i]+B.x*ratioB[i]+C.x*ratioC[i];
- float py = A.y*ratioA[i]+B.y*ratioB[i]+C.y*ratioC[i];
- vertex(px,py);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement