Slit Scan Variation - Problem with Array


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?

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");;

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

    frameBuffer[i] = new PImage();
void draw() {
  if (movie.available()) {
    movieTime = (increase * movieFrameTime) % movie.duration(); 
  for (int i= 0; i<frameBuffer.length-1; i++)
  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;


1 Like


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:

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:

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:

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


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

1 Like