Loading...
Logo
Processing Forum
code:


int data[] = {
  199, 
  190, 
  180, 
  170, 
  160, 
  150, 
  140, 
  130, 
  120, 
  110, 
  100, 
  110, 
  120, 
  130, 
  140, 
  150, 
  160, 
  150, 
  140, 
  130, 
  120, 
  110, 
  100, 
  90, 
  80, 
  70, 
  60, 
  50, 
  40, 
  30, 
  20, 
  10, 
  05, 
  10, 
  20, 
  30, 
  40, 
  50, 
  60, 
  70, 
  80, 
  90, 
  100, 
  110, 
  120, 
  130, 
  140, 
  150, 
  160, 
  170, 
  180, 
  190, 
  200, 
  205, 
  210, 
  215, 
  220, 
  225, 
  230, 
  225, 
  220, 
  215, 
  210, 
  205, 
  200, 
  195, 
  190, 
  185, 
  180, 
  175, 
  170, 
  170, 
  170, 
  170, 
  170, 
  170, 
  170, 
  170, 
  170, 
  170, 
  170, 
  165, 
  160, 
  155, 
  150, 
  145, 
  140, 
  145, 
  150, 
  155, 
  160, 
  165, 
  170, 
  175, 
  180, 
  185, 
  190, 
  195, 
  200, 
  190, 
  180, 
  170, 
  160, 
  150, 
  160, 
  175, 
  175, 
  175, 
  175, 
  175, 
  175, 
  175, 
  175, 
  180, 
  185, 
  190, 
  185, 
  180, 
  175, 
  175, 
  175, 
  170, 
  165, 
  160, 
  155, 
  150, 
  155, 
  160, 
  165, 
  170, 
  175, 
  180, 
  185, 
  175, 
  165, 
  155, 
  145, 
  135, 
  125, 
  115, 
  105, 
  95, 
  85, 
  75, 
  65, 
  75, 
  85, 
  95, 
  105, 
  115, 
  125, 
  135, 
  145, 
  155, 
  165, 
  175, 
  185, 
  195, 
  200, 
  203, 
  206, 
  209, 
  212, 
  215, 
  218, 
  221, 
  224, 
  227, 
  230, 
  227, 
  224, 
  221, 
  218, 
  215, 
  212, 
  209, 
  206, 
  203, 
  200, 
  190, 
  180, 
  170, 
  170, 
  170, 
  170, 
  170, 
  170, 
  170, 
  170, 
  170, 
  170, 
  170, 
  170, 
  175, 
  180, 
  185, 
  190, 
  195, 
  200, 
  199, 
  198, 
  197, 
  196, 
  195, 
  194, 
  193, 
  192, 
  191, 
  190, 
  189, 
  188, 
  187, 
  186, 
  185, 
  184, 
  183, 
  182, 
  181, 
  180, 
  182, 
  184, 
  186, 
  188, 
  190, 
  192, 
  194, 
  196, 
  198, 
  200, 
  202, 
  204, 
  206, 
  208, 
  210, 
  212, 
  214, 
  216, 
  218, 
  219, 
  220, 
  222, 
  224, 
  226, 
  228, 
  230, 
  232, 
  234, 
  236, 
  238, 
  240, 
  242
};





void setup() {
  size(500, 400);
  smooth();
  strokeWeight(1);
  frameRate(25);
}


void draw() {

 

  background(164, 200, 250);
  stroke(1);

  line(0, 200, 600, 200);

  for ( int i = 0; i < data.length; i++) {

       line(2*i, 200, 1.5*i, data[i]);
    stroke( ((mouseX==2*i)&&(between(mouseY, 300, data[i])))?0:255, 255, 255 );

  }
    
  
  }


boolean between( int target, int bound1, int bound2 ) {
  if ( target >= bound1 && target <= bound2 ) { 
    return( true );
  }
  if ( target <= bound1 && target >= bound2 ) { 
    return( true );
  }
  return( false );
 
}



Is it possible to get the array to rotate along the line(0, 200, 600, 200); ?

Replies(2)

What do you mean by "rotate along the line" ? Usually a rotation is done around a center point. Do you mean a "reflection symmetry" (line symmetry) ?
If this is the last case, create a new int array (let's say sdata) of the same length as data and then for each index i, you set: sdata[i] = 400 - data[i] (where 400 = your screen's height)
You cannot rotate an array... You can rotate a shape, perhaps drawn from data coming from an array. But as said, you rotate around a point (at least in 2D).