Trouble on array's [COMPLICATED]

First, we want to correct this issue:

I told you what to do. Does your println() come out now?


Second, we want to color the column. I have given you code for this to. Do you know where it belongs into your code?

The i comes from the for-loop.

I think you can figure this out now.

i think one problem might be if
you want the column select circles
and the row select circles
as 2 independent option groups ( only one of them can be selected )
also should be possible to UNSELECT them too.

here independent from the rect array / palette select i made in your last post:

a new circle class what knows its own array and can do the option group internally.

int xC = 60, yC = 80, dC = 15;
int off=20, w = 23, rows = 12, cols = 8;
int selR,selC;

Circle[] row = new Circle[rows];
Circle[] col = new Circle[cols];

void setRow() {
  for (int i = 0; i < row.length; i++)
    row[i] = new Circle(xC, yC+i*w, dC, i,row);
}

void setCol() {
  for (int i = 0; i < col.length; i++)
    col[i] = new Circle(off+xC+i*w, yC-off, dC, i,col);
}

void drawRow() {
  for (int i = 0; i < row.length; i++)
    row[i].display();
}

void drawCol() {
  for (int i = 0; i < col.length; i++)
    col[i].display();
}

class Circle {
  float xC, yC, dC;
  boolean sel=false;
  int idx;
  Circle[] me;
  
  Circle(float _xC, float _yC, float _dC, int _idx, Circle[] _me) {
    xC = _xC;
    yC = _yC;
    dC = _dC;
    idx = _idx;
    me = _me;
  }

  void display() {
    sel();
    push();
    strokeWeight(1);
    stroke(200, 200, 200);
    if (over()) {
      strokeWeight(3);
      stroke(200, 0, 0);
    }
    if ( sel ) fill(200, 0, 0);
    else       fill(0);
    circle(xC, yC, dC);
    pop();
  }

  boolean over() {
    return( dist(mouseX, mouseY, xC, yC) < dC/2 );
  }

  void sel() {
    if (over() && !sel ) {
      if (mousePressed && mouseButton == LEFT) {
        sel=true;        
        for ( int i =0; i < me.length;i++ ) if ( i != idx ) me[i].sel=false; // option group reset all others of my group
        println("sel: "+idx);
      }
    }
    if (over() && sel ) {
      if (mousePressed && mouseButton == RIGHT) {
        sel=false;
        println("UNsel: "+idx);
      }
    }
  }
}

void check_RC() {
  selR = -1;
  for (int i = 0; i < row.length; i++) if ( row[i].sel ) selR = i;
  selC = -1;
  for (int i = 0; i < col.length; i++) if ( col[i].sel ) selC = i;
}

//_______________________________________main selector tool
void setup() {
  size(500, 500);
  setRow();
  setCol();
  println("use: mouse click LEFT select RIGHT unselect\nkey [t] for print");
}

void draw() {
  background(0);
  drawRow();
  drawCol();
  check_RC(); // check row and col array and set globals 
}

void keyPressed() {
  if ( key == 't' ) println("sel: row "+selR+", col "+selC);
}


@kll: thanks for interrupting

why do you post a full code when I am trying to lead him there?

Your order of code is off. The correct way is

  • vars, then setup and draw, functions, classes

Chrisir

no problem you can repair it and talk him through / or make steps,

what i needed to mention was that option group thing,
( as a optional problem )
so first OP must define the real operation function of that
two circle buttons rows
can / must there one col and one row be selected?
can there be more selected?
depending on that my idea can be ignored.

otherwise

for ( int i =0; i < me.length;i++ ) if ( i != idx ) me[i].sel=false;

will work, but how it can be teached?

I appreciate this.

Thank you!

Greetings!

Thank you all. This was very helpful. I think I’m starting to understand it all. I very much enjoyed being lead through this by you. Thank you Chrisir and kll for your guidance.

But did you solve it?

Do both row of circles mark the entire row or column respectively?

Shall I post my way?

I have it almost solved but I believe my understanding of it due to yours and kll’s explanation I believe I can figure the rest out on my own. Thank you though. If I do run into any other problems I’ll be sure to let you know!