# Create a table of values

**URL:** <https://discourse.processing.org/t/create-a-table-of-values/19796>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [April 15, 2020, 8:35am UTC](https://discourse.processing.org/t/create-a-table-of-values/19796 "2020-04-15T08:35:12Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![marethyu](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/marethyu/32/8830_2.png) [@marethyu](https://discourse.processing.org/u/marethyu)\
**Post date:** [April 15, 2020, 8:35am UTC](https://discourse.processing.org/t/create-a-table-of-values/19796/1 "2020-04-15T08:35:12Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![marethyu](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/marethyu/32/8830_2.png) [@marethyu](https://discourse.processing.org/u/marethyu)\
**Post date:** [April 15, 2020, 8:52am UTC](https://discourse.processing.org/t/create-a-table-of-values/19796/2 "2020-04-15T08:52:20Z")

</div>

```auto
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

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [April 15, 2020, 10:00am UTC](https://discourse.processing.org/t/create-a-table-of-values/19796/3 "2020-04-15T10:00:30Z")

</div>

Hello,

Check out the resources below.

[https://processing.org/tutorials/data/](https://processing.org/tutorials/data/)

> **[Table / Reference](https://processing.org/reference/table)**
>
> Table objects store data with multiple rows and columns, much like in a traditional spreadsheet. Tables can be generated from scratch, dynamically, or using data from an existing file. Tables c…

> **[Arrays](https://processing.org/tutorials/arrays/)**
>
> How to store and access data in array structures.

> **[Array / Reference](https://processing.org/reference/array)**
>
> An array is a list of data. It is possible to have an array of any type of data. Each piece of data in an array is identified by an index number representing its position in the array. The first eleme…

> **[ArrayList / Reference](https://processing.org/reference/arraylist)**
>
> An ArrayList stores a variable number of objects. This is similar to making an array of objects, but with an ArrayList, items can be easily added and removed from the ArrayList and it is…

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

> **Resources**
>
> I encourage you to review the resources available here:
> 
> - The Processing website has references, examples, tutorials, etc.  
> [https://processing.org/](https://processing.org/)
> - Those available with the Processing PDE (IDE).  
> An exploration of the tabs will reveal what is available; there are libraries and examples there.
> - The Coding Train  
> [https://www.youtube.com/channel/UCvjgXvBlbQiydffZU7m1\_aw](https://www.youtube.com/channel/UCvjgXvBlbQiydffZU7m1_aw)  
> [https://thecodingtrain.com/](https://thecodingtrain.com/)
> - Happy Coding  
> [Processing Tutorials - Happy Coding](https://happycoding.io/tutorials/processing/)
> - The Processing Foundation  
> [https://processingfoundation.org/](https://processingfoundation.org/)  
> Check out the tabs.  
> In the education tab, there is a reference to the Coding Train.

`:)`

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [April 15, 2020, 10:02am UTC](https://discourse.processing.org/t/create-a-table-of-values/19796/4 "2020-04-15T10:02:32Z")

</div>

Hello,

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

`:) `

---

<div class="post-metadata">

**Author:** ![marethyu](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/marethyu/32/8830_2.png) [@marethyu](https://discourse.processing.org/u/marethyu)\
**Post date:** [April 15, 2020, 10:02am UTC](https://discourse.processing.org/t/create-a-table-of-values/19796/5 "2020-04-15T10:02:54Z")

</div>

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”

---

<div class="post-metadata">

**Author:** ![marethyu](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/marethyu/32/8830_2.png) [@marethyu](https://discourse.processing.org/u/marethyu)\
**Post date:** [April 15, 2020, 10:05am UTC](https://discourse.processing.org/t/create-a-table-of-values/19796/6 "2020-04-15T10:05:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [April 15, 2020, 10:09am UTC](https://discourse.processing.org/t/create-a-table-of-values/19796/7 "2020-04-15T10:09:59Z")

</div>

Hello,

Please go through the resources:

> **Resources**
>
> I encourage you to review the resources available here:
> 
> - The Processing website has references, examples, tutorials, etc.  
> [https://processing.org/](https://processing.org/)
> - Those available with the Processing PDE (IDE).  
> An exploration of the tabs will reveal what is available; there are libraries and examples there.
> - The Coding Train  
> [https://www.youtube.com/channel/UCvjgXvBlbQiydffZU7m1\_aw](https://www.youtube.com/channel/UCvjgXvBlbQiydffZU7m1_aw)  
> [https://thecodingtrain.com/](https://thecodingtrain.com/)
> - Happy Coding  
> [Processing Tutorials - Happy Coding](https://happycoding.io/tutorials/processing/)
> - The Processing Foundation  
> [https://processingfoundation.org/](https://processingfoundation.org/)  
> Check out the tabs.  
> In the education tab, there is a reference to the Coding Train.

One example:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/e/e59546a722362316d3822874eeca8381400e6ea9.png)

`:)`

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [April 15, 2020, 11:30am UTC](https://discourse.processing.org/t/create-a-table-of-values/19796/8 "2020-04-15T11:30:22Z")

</div>

example:

```auto
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);
}

```

---

<div class="post-metadata">

**Author:** ![marethyu](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/marethyu/32/8830_2.png) [@marethyu](https://discourse.processing.org/u/marethyu)\
**Post date:** [April 15, 2020, 12:05pm UTC](https://discourse.processing.org/t/create-a-table-of-values/19796/9 "2020-04-15T12:05:44Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [April 15, 2020, 12:12pm UTC](https://discourse.processing.org/t/create-a-table-of-values/19796/10 "2020-04-15T12:12:16Z")

</div>

I don’t know

I guess

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [April 15, 2020, 1:25pm UTC](https://discourse.processing.org/t/create-a-table-of-values/19796/11 "2020-04-15T13:25:56Z")

</div>

> [@marethyu](#):
>
> 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?

You had me at capacitor. `:)`

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

Example:

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

```

Example:

```auto
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);
  }

```

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/3/3591fc1809c7fd2af864e847fedf510bb26905e1.png)

`:)`

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [April 15, 2020, 5:04pm UTC](https://discourse.processing.org/t/create-a-table-of-values/19796/12 "2020-04-15T17:04:22Z")

</div>

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

[https://docs.oracle.com/javase/7/docs/api/java/lang/Float.html](https://docs.oracle.com/javase/7/docs/api/java/lang/Float.html)
