# Different results with the same code on a computer and a smartphone (with used loadPixels())

**URL:** https://discourse.processing.org/t/different-results-with-the-same-code-on-a-computer-and-a-smartphone-with-used-loadpixels/39346
**Category:** Beginners
**Created:** [October 18, 2022, 7:16pm UTC](https://discourse.processing.org/t/different-results-with-the-same-code-on-a-computer-and-a-smartphone-with-used-loadpixels/39346 "2022-10-18T19:16:15Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Nik](https://avatars.discourse-cdn.com/v4/letter/n/6de8d8/32.png) [@Nik](https://discourse.processing.org/u/Nik)
#### Post date: [October 18, 2022, 7:16pm UTC](https://discourse.processing.org/t/different-results-with-the-same-code-on-a-computer-and-a-smartphone-with-used-loadpixels/39346/1 "2022-10-18T19:16:15Z")

</div>

Hello. Different results are obtained with the same code on a computer(windows 10) and a smartphone(android) with used loadPixels(). Below is an example code and screenshots.

```auto
///////////////////////////////////
function setup() {
  createCanvas(300, 300);     
	randomSeed(1);
for (let x2=0; x2<width; x2 +=100) { 
for (let y2=0; y2<height; y2 += 100) {      
 
	fill(random(200),random(55),random(155));   
   rect(x2,y2,100,100);
	 
}
}

///////
loadPixels();
background(0); 
for (let y1=0; y1<height; y1+=100) {
    for (let x1=0; x1<width; x1+=100) {
      let poz=(x1+y1*width)*4;
       
let r=pixels[poz];
let g=pixels[poz+1];
let b=pixels[poz+2];
     
fill(r,g,b);
			
  rect(x1,y1,100,100);
    }
  }
//////////
	
}
////////////////////////////////////////////

```

![PC](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/5/6/568bae2b3427f174331e043ec0862290370827e7.png)

 ![Screenshot](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/b/9/b95a27ba5b603effd989480079e3eb3dc551df8e.png)

---

<div class="post-metadata">

### Author: ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)
#### Post date: [October 18, 2022, 8:26pm UTC](https://discourse.processing.org/t/different-results-with-the-same-code-on-a-computer-and-a-smartphone-with-used-loadpixels/39346/2 "2022-10-18T20:26:48Z")

</div>

Hi @Nik,

I see that you are using [OpenProcessing](https://openprocessing.org/) to run your sketch. It may be due to the “responsiveness” of the website and how the canvas adapts to your screen size / ratio (even thought you set the canvas size… I don’t know 🤔).

Can you post a link to your sketch so we can try it on mobile? You can also test with the p5 online editor: [editor.p5js.org/](http://editor.p5js.org/)

---

<div class="post-metadata">

### Author: ![Nik](https://avatars.discourse-cdn.com/v4/letter/n/6de8d8/32.png) [@Nik](https://discourse.processing.org/u/Nik)
#### Post date: [October 19, 2022, 4:07am UTC](https://discourse.processing.org/t/different-results-with-the-same-code-on-a-computer-and-a-smartphone-with-used-loadpixels/39346/3 "2022-10-19T04:07:05Z")

</div>

Hello @josephh!  
Yes it’s openprocessing.  
Link:

> **[1111111 - NikVct - OpenProcessing](https://openprocessing.org/sketch/1699823)**

Link (p5js editor):

> **[p5.js Web Editor](https://editor.p5js.org/NikVct/sketches/1yfb2ovnE)**
>
> A web editor for p5.js, a JavaScript library with the goal of making coding accessible to artists, designers, educators, and beginners.

---

<div class="post-metadata">

### Author: ![Nik](https://avatars.discourse-cdn.com/v4/letter/n/6de8d8/32.png) [@Nik](https://discourse.processing.org/u/Nik)
#### Post date: [October 26, 2022, 5:35pm UTC](https://discourse.processing.org/t/different-results-with-the-same-code-on-a-computer-and-a-smartphone-with-used-loadpixels/39346/4 "2022-10-26T17:35:18Z")

</div>

I asked this question on stackoverflow and got an answer. I’ll leave a link here I think many will be interested

> <https://stackoverflow.com/questions/74145183/different-results-with-the-same-code-on-a-computer-and-a-smartphone/74146886#74146886>

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [October 26, 2022, 6:15pm UTC](https://discourse.processing.org/t/different-results-with-the-same-code-on-a-computer-and-a-smartphone-with-used-loadpixels/39346/5 "2022-10-26T18:15:12Z")

</div>

I think you’d be interested in checking out a sketch that uses _pixels[]_ for both Java Mode & p5js flavors:

> [@Pixels array p5.js vs java improving speed](https://discourse.processing.org/t/pixels-array-p5-js-vs-java/38623/2):
>
> If your aim was just to make it run online just know your sketch is totally convertible to [Processing.js](https://gotoloop.github.io/processing-js.github.io/): index.html: \<script defer src=https://Unpkg.com/processing-js\>\</script\> \<canvas data-src=Trig\_Pixel\_Colors.pde\>\</canvas\> As you can see from the embedded [\<iframe\>](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe) above I’ve made many changes to your Java sketch. Most important 1 was moving the K[] array initialization to setup(). After all, nothing in the K[] array changes after it’s filled w/ colors the 1st time, just like A[]. Wh…
