Spiral Flow field

edited October 2014 in How To...

image alt text

Does any one have any ideas of how this way made? I'm think its some sort of flow field but following a spiral? Is that even possible? Would like to know how you think it was made if you could share you're thoughts.

Thanks

Tagged:

Answers

  • I took a stab at it. As you can see (especially if you click and hold, which shows control points(red) and stops background(0)) each point is making a circle. You'just got to vary their rotational offsets in a spirally way, which I haven't nailed down yet.

    class Par{
      float cx, cy;
      float t;
      Par(){
        float r = random(sqrt(20),sqrt(width/2-20));
        r = r*r;
        t = random(TWO_PI);
        cx = r * cos(t);
        cy = r * sin(t);
        cx+=width/2;
        cy+=height/2;
      }
      void draw(){
        t+=.05;
        t%=TWO_PI;
        point(cx+20*cos(t),cy+20*sin(t));
        if(mousePressed){
          stroke(255,0,0);
          point(cx,cy);
          stroke(255);
        }
      }
    }
    
    Par[] pars = new Par[5000];
    void setup(){
      size(400,400);
      stroke(255);
      for(int i=0;i<pars.length;i++) pars[i] = new Par();
    }
    void draw(){
      if(!mousePressed) background(0);
      for(int i=0;i<pars.length;i++) pars[i].draw();
    }
    
  • edited October 2014

    @TfGuy44's example was a little slow in my system. Made a tweaked version replacing point() w/ set(): :ar!


    /**
     * Spiral Flow Field (v2.11)
     * by  TfGuy44 (2014/Oct/30)
     * mod GoToLoop
     *
     * forum.processing.org/two/discussion/7860/spiral-flow-field
     * studio.processingtogether.com/sp/pad/export/ro.9$u0c$3ioIJIw/latest
     */
    
    static final int QTY = 5120, FPS = 60;
    final Par[] pars = new Par[QTY];
    
    void setup() {
      size(768, 768, JAVA2D);
      frameRate(FPS);
      noSmooth();
    
      for (int i = 0; i != QTY; pars[i++] = new Par());
    }
    
    void draw() {
      if  (!mousePressed)  background(0);
      for (Par p : pars)   p.display();
    }
    
    class Par {
      static final short HOLE = 32;
      static final float STEP = .05;
      static final color OFF  = -1, ON = #FF0000;
    
      final int cx, cy;
      float t = random(TWO_PI);
    
      Par() {
        float r = sq(random(sqrt(HOLE), sqrt(width/2 - HOLE)));
        cx = (int)(width/2  + r*cos(t));
        cy = (int)(height/2 + r*sin(t));
      }
    
      void display() {
        set(cx + (int)(HOLE*cos(t += STEP)), cy + (int)(HOLE*sin(t)), OFF);
        if (mousePressed)   set(cx, cy, ON);
      }
    }
    

    It can be watched online here: http://studio.processingtogether.com/sp/pad/export/ro.9$u0c$3ioIJIw/latest
    Similar sketch from @TfGuy44 too: http://studio.processingtogether.com/sp/pad/export/ro.9ZbTlw0Ak8yUR/latest

  • edited October 2014

    tf guy44 wrote:

    each point is making a circle. You'just got to vary their rotational offsets in a spirally way

    I don't think that does it.

    My theory is different:

    • the spiral consists of invisble attractors for the floating white points

    Thus you need to make one spiral (see below) of invisble attractors and then have a 2nd layer upon it with white particles that follow the attractors (also with some noise() involved).

    Best, Chrisir ;-)

  • here is the spiral

    imho those spiral particles are only the attractors. You have to lay a second swarm upon it that reacts to those attractors.

    // make a moving spiral of particles. 
    // Those particles are supposed to be the attractors for 
    // a swarm. 
    
    Particle[] pars = new Particle[360];
    
    final int densityAttractors = 1;  // 1 close to, 9 far from each other 
    final int steepnesSpiral    = 4;  // 4 is good, 14 would be very dense spiral
    
    void setup() {
    
      size(800, 800);
      stroke(255);
    
      int j=0; // j is needed when densityAttractors!=1 
    
      for (int i=pars.length; i>0;i--) { 
        if (i%densityAttractors == 0) {
          pars[j] = new Particle( (i*steepnesSpiral)%360, i );
          j++;
        } // if
      } // for
      println ("End of setup().");
    } // func
    
    void draw() {
      if (!mousePressed) {
        background(0);
      }
      for (int i=0;i<pars.length;i++) {
        // if (pars[i]!=null)
        pars[i].draw();
      } // for
    } // func 
    
    // ========================================
    
    class Particle {
    
      float r;      // radius  // changing 
      float angle;  // angle   // const 
    
      // constr 
      Particle(float angle_, float r_) {
        angle = angle_;
        r     = r_;
      }// constr 
    
      void draw() {
    
        // draw and change here 
    
        // paint it 
        if (r>=0) {
          point(width/2+r*cos(radians(angle)), height/2+r*sin(radians(angle)));
        }
        if (mousePressed) {
          stroke(255, 0, 0); // red 
          point(width/2+r*cos(radians(angle)), height/2+r*sin(radians(angle)));
          stroke(255); // white
        }
    
        // change it 
        r++; // fly outwards
        if (r > 360) {  
          r=0;
        } // if
      } // method
    } // class 
    
    // ======================================
    
  • A big thank you everyone, was a lot more then I was expecting. I'm going to sit down with the code snipits and try to work it out. Thanks again

Sign In or Register to comment.