# Weird behaviour with loadPixels() and updatePixels()

**URL:** <https://discourse.processing.org/t/weird-behaviour-with-loadpixels-and-updatepixels/7741>\
**Category:** Coding Questions\
**Created:** [January 22, 2019, 3:19pm UTC](https://discourse.processing.org/t/weird-behaviour-with-loadpixels-and-updatepixels/7741 "2019-01-22T15:19:19Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [January 22, 2019, 4:03pm UTC](https://discourse.processing.org/t/weird-behaviour-with-loadpixels-and-updatepixels/7741/2 "2019-01-22T16:03:58Z")

</div>

try

```auto
      var c = (x+y)%255
      set(x,y,c);
        //changePixelColor(x, y, c, c, c)

```

is it what you expected?

but this looks different:

```auto

function setup() {
  createCanvas(200, 200);
  background(0);
  let d = pixelDensity();

  loadPixels();
  console.log("d "+d); //see here 2
  for (var y = 0; y < height*d; y++) {
    for (var x = 0; x < width*d; x++)
    {
      var c = (x+y)%255;
      //set(x,y,c);
      changePixelColor(x, y, c, c, c,d);
    }
  }

  updatePixels();
}

function changePixelColor(x, y, r, g, b,d)
{
  var index = (x + y * width*d) * 4;
  pixels[index + 0] = r;
  pixels[index + 1] = g;
  pixels[index + 2] = b;
  pixels[index + 3] = 255;
}

```

i think in respect of pix dens also need to change

```auto
c = (x+y)%255

```

somehow  
[http://p5js.org/reference/#/p5/pixels](http://p5js.org/reference/#/p5/pixels)

---

_[View the full topic](https://discourse.processing.org/t/weird-behaviour-with-loadpixels-and-updatepixels/7741)._
