Elements of vector field as objects
in
Programming Questions
•
1 year ago
Hi,
I want to create a vector field where each vector is an object and each object is an element in an array. But at the moment i am only trying to draw the tail of the vectors, I will hopefully be able to add a head to these vectors later. At the moment the sketch is only producing the tail of one vector and not the others.
shane
I want to create a vector field where each vector is an object and each object is an element in an array. But at the moment i am only trying to draw the tail of the vectors, I will hopefully be able to add a head to these vectors later. At the moment the sketch is only producing the tail of one vector and not the others.
- int numVectors = 16;
- Field[] vectors = new Field[numVectors];
- int r, g, b;
- void setup() {
- size(600, 300);
- int arrayx = width/5;
- int arrayy = height/4;
- smooth();
- noStroke();
- //The following 'for' loops populate the objects
- for (int i = 0; i < 16; i++) {//i is the object element number
- for (int j = 0; j < 5; j++) {//j is for the x coordinate
- for (int k = 0; k < 5; k++) {//k is for the y coordinate
- // x1, y1, x2, y2
- vectors[i] = new Field(10*j, 10*k, (10*j)+10, (10*k)+10);
- }
- }
- }
- }
- void draw() {
- frameRate(24);
- stroke(1);
- background(#DAEBF2);
- for (int i = 0; i < 16; i++) {
- vectors[i].plot();
- }
- }
- class Field {
- float x1, y1, x2, y2;
- //Constructor
- Field(float x1pos, float y1pos, float x2pos, float y2pos) {
- x1 = x1pos;
- y1 = y1pos;
- x2 = x2pos;
- y2 = y2pos;
- }
- void plot() {
- line(x1, y1, x2, y2);//this is just as an example
- }
- }
shane
1