# Can't use line() and loadPixels()

**URL:** https://discourse.processing.org/t/cant-use-line-and-loadpixels/7620
**Category:** Coding Questions
**Created:** [January 18, 2019, 4:01pm UTC](https://discourse.processing.org/t/cant-use-line-and-loadpixels/7620 "2019-01-18T16:01:33Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![NirDafnai](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/nirdafnai/32/3293_2.png) [@NirDafnai](https://discourse.processing.org/u/NirDafnai)
#### Post date: [January 18, 2019, 4:01pm UTC](https://discourse.processing.org/t/cant-use-line-and-loadpixels/7620/1 "2019-01-18T16:01:33Z")

</div>

```auto
function setup() {
	let c = createCanvas(600, 600);
	c.parent('canvasParent');
	pixelDensity(1);
	background(255);
	loadPixels();
}

function mouseDragged() {
	if(mouseButton == LEFT)
	{
		strokeWeight(30);
		stroke(200, 100, 50, 255);
		line(mouseX, mouseY, pmouseX, pmouseY);
	}

}
function mouseReleased() 
{
	loadPixels();
}

```

This is the code, no matter what I do the pixels array is always filled only with (255,255,255,255).  
if I try to updatePixels() it resets my canvas

---

<div class="post-metadata">

### Author: ![Kevin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kevin/32/2297_2.png) [@Kevin](https://discourse.processing.org/u/Kevin)
#### Post date: [January 18, 2019, 4:41pm UTC](https://discourse.processing.org/t/cant-use-line-and-loadpixels/7620/2 "2019-01-18T16:41:48Z")

</div>

I’m not sure what you’re expecting. When I run this code I can draw pixels to the screen:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/0/05dbdedbdbbcbbd4b56f4d4568d5bade3524306d.png)

What do you expect the `loadPixels()` function to do by itself? Can you please post a [MCVE](https://stackoverflow.com/help/mcve) that demonstrates the problem?

---

<div class="post-metadata">

### Author: ![NirDafnai](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/nirdafnai/32/3293_2.png) [@NirDafnai](https://discourse.processing.org/u/NirDafnai)
#### Post date: [January 18, 2019, 4:45pm UTC](https://discourse.processing.org/t/cant-use-line-and-loadpixels/7620/3 "2019-01-18T16:45:17Z")

</div>

I am planning to do a flood-fill algorithm for my paint application.  
I want the pixel array to be updated to the lastest line drawn so I could work on it with my flood fill function.  
However, when I draw a line and log the pixel array to the console, the pixel array is not updated with the line and only the values 255 appear in the array (the line is 200, 100, 50, 255).

 ![2019-01-18_18-50-40](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/0/088f53fd638fe083b2d040058e28b312ae1d9110.gif)

```auto
function setup() {
	let c = createCanvas(600, 600);
	c.parent('canvasParent');
	pixelDensity(1);
	background(255);
	loadPixels();
}

function mouseDragged() {
	if(mouseButton == LEFT)
	{
		strokeWeight(30);
		stroke(200, 100, 50, 255);
		line(mouseX, mouseY, pmouseX, pmouseY);
	}

}
function mouseReleased() 
{
	loadPixels();
	console.log(pixels)
}

```

---

<div class="post-metadata">

### Author: ![Kevin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kevin/32/2297_2.png) [@Kevin](https://discourse.processing.org/u/Kevin)
#### Post date: [January 18, 2019, 10:48pm UTC](https://discourse.processing.org/t/cant-use-line-and-loadpixels/7620/4 "2019-01-18T22:48:26Z")

</div>

You have an extra call to `loadPixels()` in your `setup()` function. Removing it seems to fix your problem.

I’m not sure why this is the case. You might look through the P5.js source code to figure it out.

Also note that you can use the `get()` function to get the color at a specific point.

---

<div class="post-metadata">

### Author: ![NirDafnai](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/nirdafnai/32/3293_2.png) [@NirDafnai](https://discourse.processing.org/u/NirDafnai)
#### Post date: [January 19, 2019, 6:36am UTC](https://discourse.processing.org/t/cant-use-line-and-loadpixels/7620/5 "2019-01-19T06:36:38Z")

</div>

Doesn’t solve my problem unfortunately

 ![2019-01-19_08-35-49](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/d/dcfa70ca35f45f989a1f6863b45b67057d9772e9.gif)

---

<div class="post-metadata">

### Author: ![Kevin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kevin/32/2297_2.png) [@Kevin](https://discourse.processing.org/u/Kevin)
#### Post date: [January 19, 2019, 5:16pm UTC](https://discourse.processing.org/t/cant-use-line-and-loadpixels/7620/6 "2019-01-19T17:16:44Z")

</div>

I’m not sure. It works fine for me. The only other difference is that I removed the `c.parent('canvasParent');` line.

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/4/4d9e481cdc403744d59ba49e34809a634c4ca777.png)
