# Help with this Processing / Java syntax

**URL:** <https://discourse.processing.org/t/help-with-this-processing-java-syntax/24922>\
**Category:** Beginners\
**Created:** [October 26, 2020, 3:47pm UTC](https://discourse.processing.org/t/help-with-this-processing-java-syntax/24922 "2020-10-26T15:47:24Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![aaronm](https://avatars.discourse-cdn.com/v4/letter/a/bbce88/32.png) [@aaronm](https://discourse.processing.org/u/aaronm)\
**Post date:** [October 26, 2020, 3:47pm UTC](https://discourse.processing.org/t/help-with-this-processing-java-syntax/24922/1 "2020-10-26T15:47:24Z")

</div>

Hello, I’m new to Processing and Java. I’m following along with the “Generative Design” book (first edition / Java / Processing version of the book) and I’ve come across some syntax which I’m unsure about. I’m not sure if this is Processing-specific, or a general Java question, hence asking for help (as I’m not sure where to go to help myself 🙂)

```auto
int tileCountX = 10;
int tileCountY = 10;

color[] colorsLeft = new color[tileCountY];
color[] colorsRight = new color[tileCountY];
color[] colors;

```

In this case, what is `new color[tileCountY]` doing? I’m aware that `color` is a processing function, but I’m confused by the array syntax in combination with the `new` keyword. Are we instantiating a new color array, with a length equal to `tileCountY`?

Here’s the rest of the code for the sketch:

```auto
int tileCountX = 10;
int tileCountY = 10;

color[] colorsLeft = new color[tileCountY];
color[] colorsRight = new color[tileCountY];
color[] colors;

void shakeColors() {
  for (int i = 0; i < tileCountY; i++) {
    colorsLeft[i] = color(random(0, 60), random(0, 100), 100);
    colorsRight[i] = color(random(160, 190), 100, random(0, 100));
  }
}

void mouseReleased() {
  shakeColors();
}

void setup() {
  size(800, 800);
  colorMode(HSB, 360, 100, 100, 100);
  noStroke();
  shakeColors();
}

void draw() {
  tileCountX = (int) map(mouseX, 0, width, 2, 100);
  tileCountY = (int) map(mouseY, 0, height, 2, 10);
  float tileWidth = width / (float)tileCountX;
  float tileHeight = height / (float)tileCountY;
  color interCol;
  
  for (int gridY = 0; gridY < tileCountY; gridY++) {
    color col1 = colorsLeft[gridY];
    color col2 = colorsRight[gridY];
    
    for (int gridX = 0; gridX < tileCountX; gridX++) {
      float amount = map(gridX, 0, tileCountX-1, 0, 1);
      
      interCol = lerpColor(col1, col2, amount);
      
      fill(interCol);
      float posX = tileWidth * gridX;
      float posY = tileHeight * gridY;
      rect(posX, posY, tileWidth, tileHeight);
    }
  }
}

```

If it helps, I’m a JavaScript developer. Just needing a bit of help to think in Java.

Any help appreciated. Thanks!

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [October 26, 2020, 4:18pm UTC](https://discourse.processing.org/t/help-with-this-processing-java-syntax/24922/2 "2020-10-26T16:18:01Z")

</div>

> [@aaronm](#):
>
> I’m aware that `color` is a Processing function,

Yes, **color()** is a method from classes PApplet & PGraphics:

- [PApplet](http://Processing.GitHub.io/processing-javadocs/core/processing/core/PApplet.html#color-int-)
- [PGraphics](http://Processing.GitHub.io/processing-javadocs/core/processing/core/PGraphics.html#color-int-)

> [@aaronm](#):
>
> … but I’m confused by the array syntax in combination with the `new` keyword.

On that context `color` is both a Processing’s primitive datatype & keyword:

> **[color / Reference](https://processing.org/reference/color_datatype.html)**
>
> Datatype for storing color values. Colors may be assigned with get() and color() or they may be specified directly using hexadecimal notation such as #FFCC00 or 0xFFFFCC00.…

But when it’s transpiled to Java syntax `color` becomes the primitive datatype & keyword `int`:

> **[int / Reference](https://processing.org/reference/int.html)**
>
> Datatype for integers, numbers without a decimal point. Integers can be as large as 2,147,483,647 and as low as -2,147,483,648. They are stored as 32 bits of information. The first time a variable is …

In short `color` is an alias to `int`. There’s no diff. if we use 1 or the other within a “.pde” file. 😉

---

<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:** [October 26, 2020, 4:30pm UTC](https://discourse.processing.org/t/help-with-this-processing-java-syntax/24922/3 "2020-10-26T16:30:48Z")

</div>

Yes, we just make a new array of type color here

---

<div class="post-metadata">

**Author:** ![aaronm](https://avatars.discourse-cdn.com/v4/letter/a/bbce88/32.png) [@aaronm](https://discourse.processing.org/u/aaronm)\
**Post date:** [October 26, 2020, 7:24pm UTC](https://discourse.processing.org/t/help-with-this-processing-java-syntax/24922/4 "2020-10-26T19:24:30Z")

</div>

Hi @GoToLoop thanks for the links, that really answers my question. I’m aware this is basic stuff, so thanks for taking the time to help me. Cheers!

---

<div class="post-metadata">

**Author:** ![aaronm](https://avatars.discourse-cdn.com/v4/letter/a/bbce88/32.png) [@aaronm](https://discourse.processing.org/u/aaronm)\
**Post date:** [October 26, 2020, 7:28pm UTC](https://discourse.processing.org/t/help-with-this-processing-java-syntax/24922/5 "2020-10-26T19:28:08Z")

</div>

Hi @Chrisir, yes that’s what I was thinking. It’s good to be able to ask for the help with these things. Cheers 🙂

---

<div class="post-metadata">

**Author:** ![aaronm](https://avatars.discourse-cdn.com/v4/letter/a/bbce88/32.png) [@aaronm](https://discourse.processing.org/u/aaronm)\
**Post date:** [October 26, 2020, 7:34pm UTC](https://discourse.processing.org/t/help-with-this-processing-java-syntax/24922/6 "2020-10-26T19:34:41Z")

</div>

I’ve also realised I could have used `printArray` to inspect the value of `colorsLeft` here. Thanks again.

---

<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:** [October 26, 2020, 8:15pm UTC](https://discourse.processing.org/t/help-with-this-processing-java-syntax/24922/7 "2020-10-26T20:15:00Z")

</div>

There is also a tutorial about arrays
