# Slit Scan Variation - Problem with Array

**URL:** https://discourse.processing.org/t/slit-scan-variation-problem-with-array/9541
**Category:** Libraries
**Created:** [March 22, 2019, 8:38pm UTC](https://discourse.processing.org/t/slit-scan-variation-problem-with-array/9541 "2019-03-22T20:38:30Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Luis\_luethi](https://avatars.discourse-cdn.com/v4/letter/l/f17d59/32.png) [@Luis\_luethi](https://discourse.processing.org/u/Luis_luethi)
#### Post date: [March 22, 2019, 8:38pm UTC](https://discourse.processing.org/t/slit-scan-variation-problem-with-array/9541/1 "2019-03-22T20:38:30Z")

</div>

Today I was working on a slit scan variation to get an animated slit scan. My goal is, that a movement goes through a video and every slice is updated from the video and shows a different time. like running the video from 120 different starting position and only showing slices of each of them from different moment.

The way I try to achive this is by saving parts of the video as images to an array and continously add images to the array and remove images from it. Then I want to get() of every image in the array a part and update the images in the array.  
like this:  
get from index a:  
x1(a)\* width  
x2(a)\* width  
by updating the array I hope to get the movement.

But, when I set the array Sizesize (int fBm) to something like 120, it only return a black screen. When I set it to 5, I get something like 30 slices, even though I set the slice to height/array.length (int fBm).

Any Advide?

```auto
import processing.video.*;
Movie movie;
int movieFPS=25;
float increase = 160;
float movieFrameTime = 1.0/movieFPS; 
float movieTime; 

int fBm = 60;
PImage[] frameBuffer = new PImage[fBm];
int frameNumber = 0;

int slice = height/fBm;//height/images.length;
int ypos =0;

PImage display;

void setup() {
  size(720, 1280);
  movie = new Movie(this, "DSC_0054.mp4");
  
  movie.play();

  background(0);
  frameRate(25);
  for (int i=frameBuffer.length-1; i>0; i--) {

    frameBuffer[i] = new PImage();
  }
}
void draw() {
  if (movie.available()) {
    movieTime = (increase * movieFrameTime) % movie.duration(); 
    movie.jump(movieTime); 
    movie.read();
  }
  for (int i= 0; i<frameBuffer.length-1; i++)
  {
    frameBuffer[i]=frameBuffer[i+1];
  }
  frameBuffer[frameBuffer.length-1] = movie.get(0, 0, width, height);

  for (int i = 0; i<frameBuffer.length; i ++) {
    display = frameBuffer[i].get(0, ypos, width, slice);
    image(display, 0, ypos);
    ypos += slice; 
    if (ypos >= height) {
      ypos =0;
    }
  }

  increase+=1;
}

```

---

<div class="post-metadata">

### Author: ![figraham](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/figraham/32/4161_2.png) [@figraham](https://discourse.processing.org/u/figraham)
#### Post date: [March 24, 2019, 8:09pm UTC](https://discourse.processing.org/t/slit-scan-variation-problem-with-array/9541/2 "2019-03-24T20:09:51Z")

</div>

> [@Luis\_luethi](#):
>
> int slice = height/fBm;//height/images.length;

I believe this line is the problem. If you use height or width before setup it will be set to 100 by default. You can see this by running this code:

```auto
int a = height;

void setup() {
  size(200, 200);
  println(a); // prints 100
}

```

There are two ways to solve this problem 2 ways:

First is really simple just move the variable assignment into the setup method. Like:

```auto
int a;

void setup() {
  size(200, 200);
  a = height;
  println(a); // prints 200
}

```

Second is to use variables to define the size which is a little more complicated because you have to set the size in `settings()` but it’s not too bad. However with this method I always use my WIDTH and HEIGHT variables throughout the code because it won’t fix bugs like this. Here’s what that would look like:

```auto
int WIDTH = 200;
int HEIGHT = 200;

int a = HEIGHT;
// int a = height; would still print 100

void settings() {
  size(WIDTH, HEIGHT);
}

void setup() {
  println(a); // prints 200
}

```

---

<div class="post-metadata">

### Author: ![Luis\_luethi](https://avatars.discourse-cdn.com/v4/letter/l/f17d59/32.png) [@Luis\_luethi](https://discourse.processing.org/u/Luis_luethi)
#### Post date: [March 24, 2019, 9:28pm UTC](https://discourse.processing.org/t/slit-scan-variation-problem-with-array/9541/3 "2019-03-24T21:28:59Z")

</div>

Ah, I did not know that. Thanks a lot. That was not the first time this happend to me 🙂 now on the first glance it seems to work as i wished.
