# flowField:Defining a vector from a table

**URL:** <https://discourse.processing.org/t/flowfield-defining-a-vector-from-a-table/33164>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [October 29, 2021, 5:26pm UTC](https://discourse.processing.org/t/flowfield-defining-a-vector-from-a-table/33164 "2021-10-29T17:26:38Z")\
**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:** [October 29, 2021, 5:26pm UTC](https://discourse.processing.org/t/flowfield-defining-a-vector-from-a-table/33164/1 "2021-10-29T17:26:38Z")

</div>

Hi!

I found a Perlin Noise code on Github which I would like to tweak for an art project at school.

I would like to add an new Pvector forcefield which is based on a some x,y coordinates I have in a .csv file. I would like to keep the original flowfield, and add a new flowfield in the code.

The main challenge (as far as I can see) is to convert the x,y coordinates into vectors with the right direction.

Any help would be appreciated!

Hers the original code which I found from a youtube-video from The Coding Train.

int scl, cols, rows;  
float inc, zinc, zoff;  
Particle[] particles;  
PVector[] flowField;  
StopWatch sw;

void setup() {  
//Display params  
colorMode(HSB);  
background(255);  
size(1920,1080,P2D);  
frameRate(30);

//Variables  
scl = 40;  
inc = 0.1;  
zinc = 0.0001;  
zoff = 0;

//Field grid  
cols = int(width/scl);  
rows = int(height/scl);

//flowfield and particles  
particles = new Particle[5000];  
flowField = new PVector[cols\*rows];  
CreateParticles();

//Timekeeper  
sw = new StopWatch();  
sw.Start();  
}

void Reset() {  
background(255);  
for (Particle p : particles) {  
p.Reset();  
}  
sw.Restart();  
}

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 = noise(xoff, yoff, zoff)_TWO\_PI_4;  
PVector v = PVector.fromAngle(angle).setMag(1);  
flowField[index] = v;  
xoff+= inc;  
}  
yoff +=inc;  
zoff +=zinc;  
}

FlowFieldParticles(flowField);  
}

void CreateParticles() {  
for (int i=0; i\<particles.length; i++) {  
particles[i] = new Particle();  
}  
}

void FlowFieldParticles(PVector[] flowField) {  
for (Particle p : particles) {  
p.FollowFlow(flowField);  
p.Update();  
p.EdgeCheck();  
p.Show();  
}  
}
