# Brand New the Processing - Need help!

**URL:** https://discourse.processing.org/t/brand-new-the-processing-need-help/43286
**Category:** Beginners
**Tags:** homework
**Created:** [November 22, 2023, 9:12pm UTC](https://discourse.processing.org/t/brand-new-the-processing-need-help/43286 "2023-11-22T21:12:32Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Amamallama](https://avatars.discourse-cdn.com/v4/letter/a/b487fb/32.png) [@Amamallama](https://discourse.processing.org/u/Amamallama)
#### Post date: [November 22, 2023, 9:12pm UTC](https://discourse.processing.org/t/brand-new-the-processing-need-help/43286/1 "2023-11-22T21:12:32Z")

</div>

```auto
 PImage img;

void setup() {
  size(1000, 1000);
  img = loadImage( "rickroll.jpg" );
}

void draw() {
  loadPixels();
  img.loadPixels();
  
  for (int x = 0; x < img.width; x++ ) {
    for (int y = 0; y < img.height; y++ ) {
     
      int loc = x + y*img.width;

      float r = red (img.pixels[loc]);
      float g = green(img.pixels[loc]);
      float b = blue (img.pixels[loc]);

   
      float distance = dist(x, y, mouseX, mouseY);

      float adjustBrightness = map(distance, 0, 50, 8, 0);
      r *= adjustBrightness;
      g *= adjustBrightness;
      b *= adjustBrightness;

     
      r = constrain(r, 0, 255);
      g = constrain(g, 0, 255);
      b = constrain(b, 0, 255);

     
      color c = color(r, g, b);
      pixels[loc] = c;
    }
  }

  updatePixels();
}

```

The file rickroll.jpg is in the right place, but Processing says that  
ArrayIndexOutOfBoundsException: Index 40600 out of bounds for length 40000

for this line: pixels[loc] = c;  
I know this is beginner stuff. My brain is just having the hardest time right now. Can you help?

---

<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: [November 22, 2023, 9:30pm UTC](https://discourse.processing.org/t/brand-new-the-processing-need-help/43286/2 "2023-11-22T21:30:09Z")

</div>

> [@Amamallama](#):
>
> `size(1000, 1000);`

> [@Amamallama](#):
>
> `int loc = x + y*img.width;`

> [@Amamallama](#):
>
> `pixels[loc] = c;`

How do you know your “rickroll.jpg” is 1000 x 1000?

---

<div class="post-metadata">

### Author: ![Amamallama](https://avatars.discourse-cdn.com/v4/letter/a/b487fb/32.png) [@Amamallama](https://discourse.processing.org/u/Amamallama)
#### Post date: [November 22, 2023, 9:31pm UTC](https://discourse.processing.org/t/brand-new-the-processing-need-help/43286/3 "2023-11-22T21:31:10Z")

</div>

Yeah, ive no idea what size it is. 🤦‍♀️

---

<div class="post-metadata">

### Author: ![Amamallama](https://avatars.discourse-cdn.com/v4/letter/a/b487fb/32.png) [@Amamallama](https://discourse.processing.org/u/Amamallama)
#### Post date: [November 22, 2023, 9:31pm UTC](https://discourse.processing.org/t/brand-new-the-processing-need-help/43286/4 "2023-11-22T21:31:58Z")

</div>

How do I find that out?

---

<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: [November 22, 2023, 9:51pm UTC](https://discourse.processing.org/t/brand-new-the-processing-need-help/43286/5 "2023-11-22T21:51:23Z")

</div>

A more streamlined approach is to make canvas’ **size()** match the image’s _width_ & _height_ dimensions inside callback **settings()**:

> **[settings() / Reference](https://processing.org/reference/settings_.html)**
>
> The settings() function is new with Processing 3.0. It's not needed in most sketches. It's only useful when it's absolutely necessary to define the parameters to size() with a variable. …

```auto
static final String IMAGE_FILENAME = "rickroll.jpg";
PImage img;

void settings() {
  img = loadImage(IMAGE_FILENAME);
  size(img.width, img.height);
}

```

---

<div class="post-metadata">

### Author: ![Amamallama](https://avatars.discourse-cdn.com/v4/letter/a/b487fb/32.png) [@Amamallama](https://discourse.processing.org/u/Amamallama)
#### Post date: [November 22, 2023, 10:22pm UTC](https://discourse.processing.org/t/brand-new-the-processing-need-help/43286/6 "2023-11-22T22:22:38Z")

</div>

Hmm. Where does the settings callback go? I am not sure how that works.

---

<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: [November 23, 2023, 3:38am UTC](https://discourse.processing.org/t/brand-new-the-processing-need-help/43286/7 "2023-11-23T03:38:09Z")

</div>

Just place it before setup ()

Delete size command in setup () maybe

---

<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: [November 23, 2023, 3:42am UTC](https://discourse.processing.org/t/brand-new-the-processing-need-help/43286/8 "2023-11-23T03:42:41Z")

</div>

Check [settings() / Reference / Processing.org](https://processing.org/reference/settings_.html)
