# Simple live capture and scanner effect with mouse

**URL:** https://discourse.processing.org/t/simple-live-capture-and-scanner-effect-with-mouse/6299
**Category:** Libraries
**Created:** [December 4, 2018, 8:56pm UTC](https://discourse.processing.org/t/simple-live-capture-and-scanner-effect-with-mouse/6299 "2018-12-04T20:56:10Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![saskia\_NL](https://avatars.discourse-cdn.com/v4/letter/s/8baadc/32.png) [@saskia\_NL](https://discourse.processing.org/u/saskia_NL)
#### Post date: [December 4, 2018, 8:56pm UTC](https://discourse.processing.org/t/simple-live-capture-and-scanner-effect-with-mouse/6299/1 "2018-12-04T20:56:10Z")

</div>

Hi all!

I hope you can help me with this! I am trying to create sort of a scanner effect. When you move the mouse from left to right you’ll move the “beam” that’s capturing. I got this simple code working so far, but now I want it to capture the part from the webcam that is actually in that same beam. So, as you can see now the “beam” moves with the mouseX, but keeps capturing the same part. How do I make it so that it captures a different part every time the mouseX moves based on where on the screen the mouseX is?

I hope it’s clear!

```auto
import processing.video.*;

Capture video;

int x = 0;

void setup(){
  size(640, 240);
  video = new Capture(this, 320, 240);
  video.start();
}

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

void draw(){
  //image(video,0,0);
  int w = video.width;
  int h = video.height;
  copy(video, w/2,0,20,h,x,0,20,h);
  
  x = mouseX;
}

```

---

<div class="post-metadata">

### Author: ![PascalAudet](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/pascalaudet/32/1903_2.png) [@PascalAudet](https://discourse.processing.org/u/PascalAudet)
#### Post date: [December 4, 2018, 9:12pm UTC](https://discourse.processing.org/t/simple-live-capture-and-scanner-effect-with-mouse/6299/2 "2018-12-04T21:12:39Z")

</div>

> [@saskia\_NL](#):
>
> How do I make it so that it captures a different part every time the mouseX moves based on where on the screen the mouseX is?

Do you mean this?:

```auto

import processing.video.*;

Capture video;

float x = 0;

void setup(){
  size(640, 240);
  video = new Capture(this, 320, 240);
  video.start();
}

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

void draw(){
  //image(video,0,0);
  int w = video.width;
  int h = video.height;
  copy(video, int(x)/2,0,20,h, int(x), 0, 20 ,h);
  
 x =mouseX; // or x =random( 0,width);   
}

```

---

<div class="post-metadata">

### Author: ![saskia\_NL](https://avatars.discourse-cdn.com/v4/letter/s/8baadc/32.png) [@saskia\_NL](https://discourse.processing.org/u/saskia_NL)
#### Post date: [December 5, 2018, 10:17am UTC](https://discourse.processing.org/t/simple-live-capture-and-scanner-effect-with-mouse/6299/3 "2018-12-05T10:17:04Z")

</div>

YES THANK YOU!!! Very helpful!!

---

<div class="post-metadata">

### Author: ![saskia\_NL](https://avatars.discourse-cdn.com/v4/letter/s/8baadc/32.png) [@saskia\_NL](https://discourse.processing.org/u/saskia_NL)
#### Post date: [December 5, 2018, 10:19am UTC](https://discourse.processing.org/t/simple-live-capture-and-scanner-effect-with-mouse/6299/4 "2018-12-05T10:19:12Z")

</div>

only one more question: how can I mirror the video?

---

<div class="post-metadata">

### Author: ![PascalAudet](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/pascalaudet/32/1903_2.png) [@PascalAudet](https://discourse.processing.org/u/PascalAudet)
#### Post date: [December 5, 2018, 2:01pm UTC](https://discourse.processing.org/t/simple-live-capture-and-scanner-effect-with-mouse/6299/5 "2018-12-05T14:01:18Z")

</div>

> [@saskia\_NL](#):
>
> how can I mirror the video?

Look this line : copy(video, int(x)/2 , 0 , 20, h, **int(abs(x-width))**, 0, 20 , h);  
This mirror the image ,but not the mouse move (of course)

Try this:

```auto
import processing.video.*;

Capture video;

float x = 0;

void setup(){
  size(640, 240);
  video = new Capture(this, 320, 240);
  video.start();
}

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

void draw(){
  int w = video.width;
  int h = video.height;
  x =mouseX;
   // copy(video, int(x)/2 , 0 , 20, h, int(x), 0, 20 , h);
   copy(video, int(x)/2 , 0 , 20, h, int(abs(x-width)), 0, 20 , h); 

}

```

---

<div class="post-metadata">

### Author: ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)
#### Post date: [December 7, 2018, 7:11pm UTC](https://discourse.processing.org/t/simple-live-capture-and-scanner-effect-with-mouse/6299/6 "2018-12-07T19:11:21Z")

</div>

Does this also resolve your related to your question here?

- [Help needed with Leap Motion and live capture](https://discourse.processing.org/t/help-needed-with-leap-motion-and-live-capture/6323)
