# Drawing using colors from camera(Pixel Array)

**URL:** <https://discourse.processing.org/t/drawing-using-colors-from-camera-pixel-array/4694>\
**Category:** Libraries\
**Created:** [October 20, 2018, 8:05pm UTC](https://discourse.processing.org/t/drawing-using-colors-from-camera-pixel-array/4694 "2018-10-20T20:05:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![spityura](https://avatars.discourse-cdn.com/v4/letter/s/a8b319/32.png) [@spityura](https://discourse.processing.org/u/spityura)\
**Post date:** [October 20, 2018, 8:05pm UTC](https://discourse.processing.org/t/drawing-using-colors-from-camera-pixel-array/4694/1 "2018-10-20T20:05:45Z")

</div>

what am I doing wrong?  
I’m trying to get rgb values from camera an draw circles with those values  
it works fine with the get function but with the pixel array it doesn’t look right

```auto
import processing.video.*;

Capture video;

float r,g,b;

void setup() { 
size(320, 240);

video = new Capture(this, 320, 240); 
video.start();
}

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

for (int x = 0; x &lt; video.width; x++) { 
for (int y = 0; y &lt; video.height; y++) { 
int loc = x + y * video.width;

r = red (video.pixels[loc]); 
g = green(video.pixels[loc]); 
b = blue (video.pixels[loc]);

color c = color(r, g, b); 
} 
}

updatePixels();
noStroke();
fill(r,g,b);
ellipse(random(width), random(height), 10, 22); 
}

```

if I use the get function it works tho  
for example

```auto
import processing.video.*; //import the video library
Capture cam; //Capture Class, ctreat an object of type Capture and call it cam

void setup() {
	background(0); //black background
	frameRate(120);
	size(displayWidth,displayHeight);
	cam = new Capture(this); //initialize the cam object
	cam.start(); //start reading from the webcam
}

void draw() {
	//we aren't using the image function because we're not actually displaying the video from webcam
	//image(cam,0,0); 	

	//every frame draw 200 circles that pull their color from the camera
	for(int i = 0; i < 500; i++) {
		//pick a random location for each circle
		float xPos = random(0,width);
		float yPos = random(0,height);
		color c = (cam.get(int(xPos),int(yPos)));	
		fill(c,50); 
		noStroke();
		ellipse(xPos, yPos, 20, 20);
	}
}

//callback function, whenever there is a new frame of video available this function is called
void captureEvent(Capture camera) {
	camera.read();
}

```

---

<div class="post-metadata">

**Author:** ![dan850](https://avatars.discourse-cdn.com/v4/letter/d/e9c0ed/32.png) [@dan850](https://discourse.processing.org/u/dan850)\
**Post date:** [October 20, 2018, 10:17pm UTC](https://discourse.processing.org/t/drawing-using-colors-from-camera-pixel-array/4694/2 "2018-10-20T22:17:06Z")

</div>

> [@spityura](#):
>
> void draw() {  
> loadPixels();  
> video.loadPixels();
> 
> for (int x = 0; x \< video.width; x++) {  
> for (int y = 0; y \< video.height; y++) {  
> int loc = x + y \* video.width;
> 
> r = red (video.pixels[loc]);  
> g = green(video.pixels[loc]);  
> b = blue (video.pixels[loc]);
> 
> color c = color(r, g, b);  
> }  
> }

I can tell you so far that your ‘c’ variable is not being used in your 1st program.
