Storing points to create gradient of shapes

Hi There!
So I am trying to create a smooth gradation of polygons using storing.
I need to dynamically change the amount of points and store them to fade consequently.
However, the code changes all the polygons at the same time…

Bellow is the full code, underneeth it - I highlighted the key moments:

int num = 60; // amnt of storing data
int  a = 0;

float mouse[] = new float[num];

int numbers[] = new int[num]; // type name[create array] =store= new type[how long is it]
//rn the array has "num" length, filled entirely with zeros 0
// numbers[4] = 100 - [index in the list] = now equals 100

//i need an array length = num, but filled with different numPoints values {5,6,7,4,3,8}
//so I dont need to create an array numPoints...




void setup() {
  size(640, 640);
  noFill();
}

void draw() {
  stroke(200, a);
  background(3, 7, 11);

int  numPoints = round(random(3,6)); //dynamically change the numPoints
  float  angle = 0;
  float  angleStep = 180.0 / numPoints;
float ptx[] = new float[numPoints];
float pty[] = new float[numPoints];
  //cycle through the array (indexes), using a different entry on each frame
  int idx = frameCount % num; //array index = framecount % num (% - reminder of what is left after division)
  mouse[idx] = dist(mouseX, mouseY, width * 0.5, height * 0.5); //each frame = each index in the list = new values

numbers[idx] = numPoints; //each frame = each index = new value
int pts = frameCount % numPoints;
  for (int i = 0; i < num; i++) {
    int m_idx = (idx + 1 + i) % num; //idx+1 is the smallest (the oldest in the array)
    
int n_idx = (idx + 1 + i) % num;

    beginShape(TRIANGLE_STRIP);
    for (int j = 0; j <= numbers[n_idx]; j++) {
      float px = (width * 0.5) + cos(radians(angle)) * mouse[m_idx];
      float py = (height * 0.5) + sin(radians(angle)) * mouse[m_idx];
      angle += angleStep;
      ptx[pts] = px;
      pty[pts] = py;
      vertex(ptx[pts], pty[pts]);
    }
    endShape();
  }

  a -= 2;
}

void mouseMoved() {
  a = 150;
}

In order to dynamically change the number of polygons (for example randomly), I am doing the following:
I create a new array before void setup
int numbers[] = new int[num];
Which means that I will have an array length = the num value.
The num here is the amount of stored data.

Now I need to fill each index of the array with different amount of polygons
in void draw :

int  numPoints = round(random(3,6)); //dynamically change the numPoints
int idx = frameCount % num;
numbers[idx] = numPoints;

to cycle through the array indexes (each frame = each index = curren numPoints).
then build the shapes based on stored polygons:

  for (int i = 0; i < num; i++) {
    int n_idx = (idx + 1 + i) % num; // /idx+1 is the smallest (the oldest in the array)
    beginShape(TRIANGLE_STRIP);
    for (int j = 0; j <= numbers[n_idx]; j++) {
      float px = (width * 0.5) + cos(radians(angle)) * mouse[m_idx];
      float py = (height * 0.5) + sin(radians(angle)) * mouse[m_idx];
      angle += angleStep;
      vertex(px, py);
    }
    endShape();
  }

but as I previously mentioned, it changes all the geometries at once, and does not store the old shapes :C
Could someone please please advice on what am I doing wrong?

p.s. Thank you @ slow_izzm for previously helping with the storing radiuses!

1 Like

I got your code to run, but I don’t think I understand what you’re trying to achieve; can you provide a bit more explanation of the behavior you’re going for?

hi Tony!

Sure.
I build the polygon geometry based on amnt of points.
I need to change the point numbers dynamically.
So I want it to gradually fade into infinity constantly changing the geometry.
Right now I have a “tunnel” of polygons that are being changed simultaneously.
However, I need to change them consequently.
To make a sort of gradual and organic change of shape.

Sorry if my English isnt perfect, I am trying my best :slight_smile:

Any thoughts? :((
Maybe I need to store the polygons somehow

I think you’re right.

It sounds like you want each polygon to fade independent of the others.

Right now, “a” is being applied to all the polygons. So you might have to creat a Polygon Object each with their own alpha. They will have to individually be created and then updated consecutively.

2 Likes

Thank you for your reply!

Can you give me any hint on how could I do that? I am not very profound…yet :slight_smile:
Should I create some new class?
Meantime, I will try to make it by my own, and post here if I succseed :slight_smile:

Here is my attempt to create a Polygon Object…
I have just started to understand how to write object-oriented stuff, but my code has a lot of issues…
Can I, please, get some help with that?

//DECLARE OBJECTS
Obj myObj1;

int num = 60; // amnt of storing data
int  a = 0;
float mouse[] = new float[num]; 
int numbers[] = new int[num]; //the array has "num" length, filled entirely with zeros 0

void setup() {
  size(600,600);
  background(255);
}

void draw() {
  stroke(200, a);
  background(3, 7, 11);
  
  //CREATE OBJECTS WITH PARAMETERS:
  myObj1 = new Obj(a,ptx[pts],pty[pts]); //color, num of polygons X, num of polygons Y
  
  int  numPoints = round(random(3,6)); //dynamically change the numPoints for each object
  
  //CALL THE OBJECT FUNCTIONS
  myObj1.drive();
  myObj1.display();
  
  a -= 2; //dynamically fade each object
}

class Obj { 
  //DATA:
  float c;
  int number;
  
  //CONSTRUCTOR + ARGUMENTS(temp):
  Obj(color tempC, int tempNumber) { //color, num of polygons
    c = tempC;
    number = tempNumber;
  }
  
  //FUCTIONALITY:
  void display() {
    noFill();
    stroke(c);
    
      for (int i = 0; i < num; i++) {
        int m_idx = (idx + 1 + i) % num; //idx+1 is the smallest (the oldest in the array)
        
        int n_idx = (idx + 1 + i) % num;
    
        beginShape(TRIANGLE_STRIP);
        for (int j = 0; j <= numbers[n_idx]; j++) {
          float px = (width * 0.5) + cos(radians(angle)) * mouse[m_idx];
          float py = (height * 0.5) + sin(radians(angle)) * mouse[m_idx];
          angle += angleStep;
          ptx[pts] = px;
          pty[pts] = py;
          vertex(ptx[pts], pty[pts]);
        }
      endShape();
      }
  }
  
  void drive() {
    float  angle = 0;
    float  angleStep = 180.0 / numPoints;
    float ptx[] = new float[numPoints];
    float pty[] = new float[numPoints];
    //cycle through the array (indexes), using a different entry on each frame
    int idx = frameCount % num; //array index = framecount % num (% - reminder of what is left after division)
    mouse[idx] = dist(mouseX, mouseY, width * 0.5, height * 0.5); //each frame = each index in the list = new values
    numbers[idx] = numPoints; //each frame = each index = new value
    int pts = frameCount % numPoints;
  }
}
  

Basically I need to create a num amount of objects, that will fade just like before, but each object will have a unique amount of polygons.

1 Like

:)

1 Like

i saw all of those, thank you