# Mirror video doodles. ArrayIndexOutOfBoundsException

**URL:** https://discourse.processing.org/t/mirror-video-doodles-arrayindexoutofboundsexception/14557
**Category:** Libraries
**Created:** [October 9, 2019, 7:01pm UTC](https://discourse.processing.org/t/mirror-video-doodles-arrayindexoutofboundsexception/14557 "2019-10-09T19:01:52Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![elom1213](https://avatars.discourse-cdn.com/v4/letter/e/54ee81/32.png) [@elom1213](https://discourse.processing.org/u/elom1213)
#### Post date: [October 9, 2019, 7:01pm UTC](https://discourse.processing.org/t/mirror-video-doodles-arrayindexoutofboundsexception/14557/1 "2019-10-09T19:01:52Z")

</div>

While I’m studying the book ‘Learning processing’, written by Daniel Shiffman, there’s keep error on my code.

```auto
import processing.video.*;
Capture video;
float x;
float y;

void setup() {
  size(352, 288);
  background(255);
  x = width/2;
  y = width/2;
  video = new Capture(this, width, height);
  video.start();
}

void captureEvent(Capture video) {
  video.read();
}

void draw() { 
  video.loadPixels();
  float nex = constrain(x + random(-20, 20), 0, video.width-1);
  float ney = constrain(y + random(-20, 20), 0, video.height-1);

  int midx = int((x+nex)/2);
  int midy = int((y+nex)/2);
  println((video.width - midx - 1) + midy * video.width);
  color c = video.pixels[(video.width - midx - 1) + midy * video.width];

  stroke(c);
  strokeWeight(6);
  line(x, y, nex, ney);

  x = nex;
  y = ney;
}

```

it just keep telling me a limited array number and also the number keep changes.

 ![%EC%A0%9C%EB%AA%A9%20%EC%97%86%EC%9D%8C-1%20%EB%B3%B5%EC%82%AC](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/1/10bb255079d947262975e26fe4c7ed337dad0bdd.jpeg)

could you help me?  
you can check this code on the book that I mentioned chapter 16 video part.

---

<div class="post-metadata">

### Author: ![Tiemen](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tiemen/32/5477_2.png) [@Tiemen](https://discourse.processing.org/u/Tiemen)
#### Post date: [October 9, 2019, 9:50pm UTC](https://discourse.processing.org/t/mirror-video-doodles-arrayindexoutofboundsexception/14557/2 "2019-10-09T21:50:07Z")

</div>

Welcome Elom,

Haven’t tested your code, but I guess the `ArrayIndexOutOfBoundException` occurs because you’re asking for a pixel that isn’t there. Your window size is 352 by 288 pixels, meaning there are 101.376 pixels in total.

---

<div class="post-metadata">

### Author: ![neilcsmith](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/neilcsmith/32/144_2.png) [@neilcsmith](https://discourse.processing.org/u/neilcsmith)
#### Post date: [October 10, 2019, 9:17am UTC](https://discourse.processing.org/t/mirror-video-doodles-arrayindexoutofboundsexception/14557/3 "2019-10-10T09:17:38Z")

</div>

Pretty sure you meant to multiply `midy` by `video.height`?

Also not sure you can assume the video pixels are not empty until the first frame is received.
