# Not sure why my array is not allowed to use a function (OOP)

**URL:** <https://discourse.processing.org/t/not-sure-why-my-array-is-not-allowed-to-use-a-function-oop/31232>\
**Category:** Beginners\
**Created:** [July 13, 2021, 12:44pm UTC](https://discourse.processing.org/t/not-sure-why-my-array-is-not-allowed-to-use-a-function-oop/31232 "2021-07-13T12:44:51Z")\
**Posts on this page:** 2\
**Page:** 2

<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:** [July 13, 2021, 9:58pm UTC](https://discourse.processing.org/t/not-sure-why-my-array-is-not-allowed-to-use-a-function-oop/31232/21 "2021-07-13T21:58:31Z")

</div>

> [@LuckyDots](#):
>
> ```auto
> // fill(black);
> fill(255);
> 
> ```

Please use black here later

- I think the time stuff properly should all go into the class so it can be different for all triangles

- Don’t use the random throughout but only initially in the constructor and when the condition is met

---

<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:** [July 14, 2021, 12:13pm UTC](https://discourse.processing.org/t/not-sure-why-my-array-is-not-allowed-to-use-a-function-oop/31232/22 "2021-07-14T12:13:35Z")

</div>

just to demonstrate the idea of objects in an array here is an example (without timer) (OOP)

- Please note that the class knows only ONE triangle. It is oblivious of the entire array. In fact you could just declare a single triangle before `setup()` without having to change the class. Good.

```auto

Triangle[] tri = new Triangle[18];

void setup() {
  size(900, 900);
  background(220);

  for (int i = 0; i < tri.length; i++) {
    float y = i*10;
    float x = 60*i;
    tri[i] = new Triangle(x, y);
  }
}//func

void draw() {
  background(220);

  for (int i = 0; i < tri.length; i++) {
    tri[i].change();
    tri[i].display();
  }
}//func

// ========================================================

class Triangle {

  // representing ONE Triangle

  int savedTime = 11;
  float totalTime = random(0, 1100);

  float black = random(255);

  float x;
  float y;

  //constr 
  Triangle(float tempX, float tempY) {
    x = tempX;
    y = tempY;
  }//constr 

  void display() {
    fill(black);
    triangle(x, y, 
      x+25, y+50, 
      x-25, y+50);
  }//method

  void change() {
    black += 1;
    if (black >= 255) {
      black = 0;
    }
  }//method
  //
}//class
//

```

[Previous page](https://discourse.processing.org/t/not-sure-why-my-array-is-not-allowed-to-use-a-function-oop/31232.md?page=1)
