Nodes System coding in Processing

Hello world! I am developing a school project that asks me to implement a node system that can be used in the production of design objects. It has to be a functional application in some field of design (product, architecture, interactive design, illustration, fashion, etc…) and in ways of generating greater complexity (the relationship between various processes, their use to determine parameters additional to the position, etc…). I have these two code options:

class Nodo{
  float x,y;
  float r;
  float amp;
  float dx, dy;
   
  Nodo(float x_, float y_, float r_, float amp_){
    x = x_;
    y = y_;
    r = r_;
    amp = amp_;
    dx = random(-2,2);
    dy = random(-2,2);
  }
  
  void mover(){
    x+=dx;
    y += dy;
  }
}

class Cubo{
  float x,y,z;
  
  Cubo(float x_, float y_){
    x = x_;
    y = y_;
    z = 0;
  }
  
  void display(){
    pushMatrix();
    translate(x,y,z);
    noStroke();
    fill(255,0,0);
    box(tam);
    popMatrix();
  }
}

ArrayList <Nodo> nodos;
ArrayList <Cubo> cubos;
int tam = 10;;
void setup(){
  size(500,500,P3D);
  background(0);
  nodos = new ArrayList<Nodo>(); 
  cubos = new ArrayList <Cubo>();
  for(int i = 0 ; i<100; i++){
    nodos.add(new Nodo(random(-width/2,width/2),random(-height/2, height/2),random(30,150),random(40)));
  }
  for(int i = -width/2; i<width/2; i+= tam){
    for(int j = -height/2 ; j<height/2;j+= tam){
      cubos.add(new Cubo(i,j));
    }
  }
  
 
}

void draw(){
  background(0);
  lights();
  translate(width/2,height/2);
  rotateX(mouseX*0.03);
  rotateY(mouseY*0.03);
  for(Cubo c:cubos){
    c.display();
  }
  for(Nodo n:nodos){
    n.mover();
  }
  
  for (Cubo c:cubos){
    c.z = 0;
    for(Nodo n:nodos){
      float distancia = dist(c.x,c.y,n.x,n.y);
      if(distancia < n.r){
        c.z+=n.amp*map(distancia,0,n.r,1,0);
      }
    }
  }
}

class Nodo{
  float x,y;
  float r;
  float amp;
  float dx,dy;
  float ro,ve,az;
  
  Nodo(float x_, float y_, float r_, float amp_){
    x = x_;
    y = y_;
    r = r_;
    amp = amp_;
    dx = random(-2,2);
    dy = random(-2,2);
    ro = random(255);
    ve = random(255);
    az = random(255);
  }
  
  void mover(){
    x+=dx;
    y+=dy;
  }
  
  void display(){
    int centroH = floor(x);
    int centroV = floor(y);
    int radio = floor(r);
    int limiteizq = (centroH - radio >0)? centroH - radio:0  ;
    int limiteder = (centroH + radio<width)? centroH + radio : width;
    int limitesup = (centroV - radio> 0)? centroV - radio: 0;
    int limiteinf = (centroV + radio<height)? centroV + radio: height;
    
    for(int i = limiteizq; i< limiteder ; i++){
      for (int j = limitesup ; j< limiteinf; j++){
        float distancia = dist(x,y,i,j);
        if(distancia<r){
          int pix = j*width + i;
          color original = pixels[pix];
          float orojo = red(original);
          float overde = green(original);
          float oazul = blue(original);
          float cantidad = amp*map(distancia,0,r,1,0);
          orojo += cantidad*ro;
          overde += cantidad*ve;
          oazul += cantidad*az;
          color nuevo = color(orojo,overde,oazul);
          pixels[pix] = nuevo;
        }
      }
    }
  } 
}

ArrayList <Nodo> nodos;
void setup(){
  size(500,500);
  background(0);
  nodos = new ArrayList<Nodo>();
  for(int i = 0 ; i<100; i++){
    nodos.add(new Nodo(random(width),random(height),random(30,150),random(0.5)));
  }
  loadPixels();
  for(Nodo n:nodos){
      n.display();
  }
  updatePixels(); 
}

I’m not exactly good at programming and it’s as far as I got my creativity, I have the idea to implement something with sound recognition and nodes but I don’t know how to carry it out, if someone could advise me and/or help me it would be phenomenal :smiley:

1 Like

Look here Looking for an old music app - #3 by Returningcustomer

1 Like

Hello,

Please format your code:
https://discourse.processing.org/faq#format-your-code

You can use the edit button (looks like a pencil):
image

:)

2 Likes

Check out the sound library and the minim library

1 Like

Yup, I’ve been checking it, but I have no idea how to implement it in the code and react to sound. I thought about using arduino but I don’t have the possibility to buy one for now :frowning:

1 Like

There is a microphone in minim library

No Arduino needed