# Time displacement / slit-scan webcam looping issue

**URL:** https://discourse.processing.org/t/time-displacement-slit-scan-webcam-looping-issue/42681
**Category:** Libraries
**Created:** [August 31, 2023, 12:03am UTC](https://discourse.processing.org/t/time-displacement-slit-scan-webcam-looping-issue/42681 "2023-08-31T00:03:26Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![codecduck](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codecduck/32/18740_2.png) [@codecduck](https://discourse.processing.org/u/codecduck)
#### Post date: [August 31, 2023, 12:03am UTC](https://discourse.processing.org/t/time-displacement-slit-scan-webcam-looping-issue/42681/1 "2023-08-31T00:03:26Z")

</div>

I have this effect on the webcam that is creating a delayed portion that grows from bottom to top. I’m pretty beginner so I don’t know where to start. I’ve been trying to get it to just continually have the slit-scan effect. Please help!

 ![test](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/8/e/8e6299d8314c1c5ea4d8d069614a5ae413b5ac0e.jpeg)

```auto
import processing.video.*;

Capture cam;
int h = 10;
int y = 0;
PImage[] history; 
int historyIndex = 0;
int offset = 0;

boolean paused = false; // Flag to control slitscan pause/resume

void setup() {
size(640, 480);
cam = new Capture(this, 640, 480);
history = new PImage[height / h];
for (int i = 0; i < history.length; i++) {
  history[i] = createImage(width, height, RGB);
}
cam.start();
background(0);
frameRate(24);
}

void captureEvent(Capture cam) {
cam.read();
if (!paused) {
  history[historyIndex].copy(cam, 0, 0, width, height, 0, 0, width, height);
  historyIndex = (historyIndex + 1) % history.length;
}
}

void draw() {
for (int i = 0; i < history.length; i++) {
  int y = i * h;
  int currentIndex = (i + offset + history.length) % history.length;
  PImage currentImage = history[currentIndex];
  copy(currentImage, 0, y, width, h, 0, y, width, h);
}

if (!paused) {
  offset++;
}
}

void mouseClicked() {
paused = !paused; // Toggle pause/resume
}

```
