Updating colorfill

Hi team,

I have an issue regarding the updating of the colorfill when using a beginShape() / endShape() function.

I have a plane ( x & y grid) which has a colorfill that changes during time (updates). It doesnt update though. When i use random(255) it does change, though when using a variable it only takes the1st (or last). the colorgrid (static looks as such:

gridopzet

Do i need to include a command that allows updtating fill colors with changing values on the x-y grid. code with example of variable that changes the grid ( in real it will be an array with data for each gridpoint (vertex) that refreshes ech iteration):

void setup() {
  size(900, 700, P3D);
  //noStroke();
}

void draw() {
  background(0);
  translate(width/4, height/1.2);

 int fillvariable= 0;
  
 for(int w=0; w< 400; w+= 25){
   for(int h=0; h> -400; h-= 25){
  
beginShape(QUADS);
  normal(0, 0, 1);
  fill(w/2, h/2, 200);
  vertex(w, h);
  
   fill(fillvariable, h/2, 200);
  vertex(w+25, h);
  
  fill(w/2, h/2, 200);
  vertex(w+25, h-25);
  
   fill(w/2, h/2, 200);
  vertex(w, h-25);
  endShape();
  
  
   fillvariable += 20;
   if( fillvariable >255)  {  fillvariable=0; }
   println(fillvariable);
   
  }
 }
}

Is this way of filling a grid the smartest way (basically its making an colored isosurface)? Might be that this way takes much memory or cpu in the way its looping. I am trying to read into shaders and how + when to use them, but at the beginning of the gpu to cpu difference and how processing uses such.

Answers

  • Please also post the code which failed to work as expected. Also note the the correct way to format code is-

    • Select your code, press ctrl + o.
    • Your code is indented 4 spaces.
    • Leave a line above and below your code.
    • Markdown will do the rest.
  • Dear L_o_t_Galaxy: Did my best to adjust it in the correct format. hope its readable in this way. warmest regards,

    Dino

  • edited January 2017

    OK.
    Did you mean to declare your fillvariable inside draw? If so, your code cannot be dynamic.

  • edited January 2017

    The variable itself is dynamically updated by a for loop that opens an array of data that will influence the color and make up the isosurface. I think the only way to do so is to hav ethem both in draw() .

    Not yet sure how to solve this using another approach in order to achieve a dynamically update color.

  • What exactly was your question anyway?

  • edited January 2017

    Dear L_o_t_Galaxy.

    The question : How can i upate the fill color data in a BeginShape() ......endShape() in which the pixels are colored by the local vertex points?

    Secondly is there a better aproach (it might be the wrong way trying to color the pixels like this)

    beginShape(QUADS);
      normal(0, 0, 1);
      fill( Variable);
      vertex(w, h);
       
       fill( Variable);
      vertex(w+25, h);
       
      fill(255, 255, 200);
      vertex(w+25, h-25);
       
       fill(255, 255, 200);
      vertex(w, h-25);
      endShape();
    

    seems only a "random(255)" will dynamically change the values. The goal is to drive the fill() command by data comming from an array that changes each iteration.

    warmest regards,

    Dino

  • No, as long as your variable is dynamically changing, the color also changes. However, note that only one edge of the square is affected by the "Variable".

  • edited January 2017

    Dear L_o_t_Galaxy, It gave me the insight i needed , from here i can build further to include the array's.

    int fillvariable= 0;
    
     void setup() {
       size(900, 700, P3D);
       //noStroke();
     }
    
     void draw() {
       background(0);
       translate(width/4, height/1.2);
    
      for(int w=0; w< 400; w+= 50){
        for(int h=0; h> -400; h-= 50){
    
     beginShape(QUADS);
       normal(0, 0, 1);
       fill(fillvariable);
       vertex(w, h);
    
        fill(fillvariable);
       vertex(w+25, h);
    
       fill(0);
       vertex(w+25, h-25);
    
        fill(0);
       vertex(w, h-25);
       endShape();
    
        fillvariable += 20;
        if( fillvariable >255)  {
          fillvariable=0;
        }
        println(fillvariable);
    
       }
      }
     }
    

    much much apreciated

  • Yes, that's what I meant. And that's why I asked why you declared your variable in draw().

Sign In or Register to comment.