Weird behaviour with loadPixels() and updatePixels()

try

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

is it what you expected?

but this looks different:


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

c = (x+y)%255

somehow
http://p5js.org/reference/#/p5/pixels

1 Like