# Insert a path into a flowfield

**URL:** <https://discourse.processing.org/t/insert-a-path-into-a-flowfield/33334>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [November 5, 2021, 1:26pm UTC](https://discourse.processing.org/t/insert-a-path-into-a-flowfield/33334 "2021-11-05T13:26:35Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sigbjorn](https://avatars.discourse-cdn.com/v4/letter/s/839c29/32.png) [@sigbjorn](https://discourse.processing.org/u/sigbjorn)\
**Post date:** [November 5, 2021, 1:26pm UTC](https://discourse.processing.org/t/insert-a-path-into-a-flowfield/33334/1 "2021-11-05T13:26:35Z")

</div>

Hi

I have an art project for my class. For this I would like to insert a path function to a flowfield.

I feel like im almost done, but cant seem to place the last puzzle.

For mye work I have been using the Coding trains tutorials on steering behavior and flowfield.

FlowfieldCode (This is the code used as basis, and the path code is adjustet to fit this): [website/CodingChallenges/CC\_024\_PerlinNoiseFlowField/Processing/CC\_024\_PerlinNoiseFlowField at main · CodingTrain/website · GitHub](https://github.com/CodingTrain/website/tree/main/CodingChallenges/CC_024_PerlinNoiseFlowField/Processing/CC_024_PerlinNoiseFlowField)

Path following Code: [noc-examples-processing/chp06\_agents/NOC\_6\_06\_PathFollowing at master · nature-of-code/noc-examples-processing · GitHub](https://github.com/nature-of-code/noc-examples-processing/tree/master/chp06_agents/NOC_6_06_PathFollowing)

I have managed to make the path according to my wishes (and function when rehersing in the steering behaviour-code). But when I try to insert the path to the flowfield code, I cant seem to find the right method.

I think i need to place the path-function in the if-function on the bottom:

```auto
void draw() {
  if (sw.GetSeconds() >= 90) {
    Reset();
  }

  float yoff = 0;
  for (int y = 0; y<rows; y++) {
    float xoff=0;
    for (int x = 0; x<cols; x++) {
      int index = x+y*cols;
      float angle = noise2(xoff, yoff, zoff,y,x);
            //float angle = noise2(xoff, yoff, zoff,y,x, Path.points);
      PVector v = PVector.fromAngle(angle).setMag(1);
      flowField[index] = v;
      xoff+= inc;
    }
    yoff +=inc;
    zoff +=zinc;
  }
  FlowFieldParticles(flowField);
  //path.display();

 }
 
 float noise2 (float xoff, float yoff, float zoff, float y, float x){
   //return noise(xoff, yoff, zoff)*TWO_PI*4;
   // if på fjellet til fjellet, gå til høyre
   if (y <= cols/3 && y >= (cols/3)-3) { // IF this - follow Path Vectors
     println("y-verdi");

     return PI;
     
   }
    return noise(xoff, yoff, zoff)*TWO_PI*4; 
 }

```

When I run this code, i get the effect i want, that the particle moves to the left in the area I have defined in the

```auto
  if (y <= cols/3 && y >= (cols/3)-3)

```

- part of the code.

But I want it to follow the path i have defined in a seperate class acording to the Coding trains tutorial.

If you need more from my code to help, please let me know.
