Create a table of values

Hi, now I’m working on a mini project which require creating a table of possible value, then use these values to calculate and draw the graph.

I have try the most ‘brutal’ way which uses just the function text(), but when it comes to the calculation part, I have to select the value by mouse clicked, then it will be put in a rectangular, and process the calculation. The way of using text() above make it pretty hard to code that part since I can not use something like table adress.

I also tried the loadTable() function, but no use.

Do you have any suggestion?

1 Like
void mestexts()
{
  fill(0, 255, 255);
  text("R= ", 30, 30);
  text("1000 ", 50, 50);
  text("2200 ", 50, 100);
  text("3300", 50, 150);
  text("4700", 50, 200);
  text("10000", 50, 250);
  text("22000", 50, 300);
  text("33000", 50, 350);
  text("47000", 50, 400);
  text("68000", 50, 450);
  text("100000", 50, 500);

  // Valeur de C
  text("C= ", 130, 30);
  text("1n ", 150, 50);
  text("2,2n", 150, 100);
  text("3,3n", 150, 150);
  text("4,7n", 150, 200);
  text("10n", 150, 250);
  text("22n", 150, 300);
  text("33n", 150, 350);
  text("47n", 150, 400);
  text("68n", 150, 450);
  text("100n", 150, 500);

In case you wonder, this is my code for the ‘table’. Kind of cheating, right? But I have no better way

1 Like

Hello,

Check out the resources below.

https://processing.org/tutorials/data/
https://processing.org/reference/Table.html
https://processing.org/tutorials/arrays/
https://processing.org/reference/Array.html
https://processing.org/reference/ArrayList.html

Do you want to store the values as strings or as numbers?

Resources

I encourage you to review the resources available here:

:)

1 Like

Hello,

Please format your code when posting as a courtesy to all of us:
https://discourse.processing.org/faq#format-your-code

:)

As array will be better since I have to use it in the calculation latter. The project require a feature like “when click on the value, it will be put on a mathematical functions, then execute that function”

Ok, this is my first post, so thanks for advice

1 Like

Hello,

Please go through the resources:

Resources

I encourage you to review the resources available here:

One example:

:)

example:

float[] list = 
  {
  1000, 
  2200, 
  3300, 
  4700, 
  10000, 
  22000, 
  33000, 
  47000, 
  68000, 
  100000
};

float result; 

void setup() {
  size(750, 750);
}

void draw() {
  background(255);
  mestexts();
  text (result, 300, 300);
}

// ----------------------------------------------------------------

void mousePressed() {
  //
  for (int i=0; i<list.length; i++) {
    if (mouseY>50*(i+1)-15&&
      mouseY<50*(i+1)+47-15) {
      //
      result=list[i]; 
      return;
    }
  }
}

void setColorFromMouse( int lower_ ) {
  if (mouseY>lower_-15&&
    mouseY<lower_+47-15)
    fill(255, 0, 0);
  else fill(0);
} 

void mestexts()
{
  // fill(0, 255, 255);
  fill(0); 
  textAlign(RIGHT); 
  text("R=", 50, 30);
  for (int i=0; i<list.length; i++) {
    setColorFromMouse( i*50+50 ); 
    text(floor(list[i]), 80, i*50+50);
  }


  //--------------------

  // Valeur de C
  fill(0);
  line(150+5, 0, 
    150+5, height);  
  textAlign(RIGHT); 
  text("C=", 150, 30);
  text("1n", 150, 50);
  text("2,2n", 150, 100);
  text("3,3n", 150, 150);
  text("4,7n", 150, 200);
  text("10n", 150, 250);
  text("22n", 150, 300);
  text("33n", 150, 350);
  text("47n", 150, 400);
  text("68n", 150, 450);
  text("100n", 150, 500);
}
1 Like

Ok thanks so much. By the way, I want to use the value very small in processing, like nano(10^-9), for ex the value of a capacitor, how can I declare it? Or I have to write like 0.00000001?

I don’t know

I guess

You had me at capacitor. :)

Take a look:
https://docs.oracle.com/javase/specs/jls/se7/html/jls-3.html#jls-3.10.2

Example:

float num1 = 6.022137e+23f;
println(num1);

Example:

void setup()
  {
  size(500, 100);
  float num1 = 4.7e-6f;
  println(num1);
  textAlign(CENTER, CENTER);
  textSize(24);
  text(nfs(num1, 1, 10), width/2, height/3-10);
  text(str(num1), width/2, 2*height/3-10);
  }

:)

3 Likes

See also the Java built-ins like Float.MIN_VALUE.

https://docs.oracle.com/javase/7/docs/api/java/lang/Float.html