Different screen sizes android


While writing a little program on android processing, I noticed that the rendering was not the same depending on the screen I was using. Here is the code:

void setup () {
background (0);

void draw () {
ellipse(width / 2, height / 1.95, height / 4.8, height / 4.8);
ellipse(width / 1.421, height / 2.365, height / 18.5, height / 18.5);
ellipse(width / 3.71824f, height / 1.73, height / 18.5, height / 18.5);

Here are the different image:

Sorry for the mistakes I use the Google Translate

Can you help me troubleshoot screen compatibility?
Thanks you.


i would assume that this is because the proportion of the screen varies between devices. I would first calculate the proportion of the screen and then i would use that info to calculate the position (and size) of the ellipses.


Sorry I did not understand, is that someone could rewrite the sketch so that the proportion is respect ?


Check this: http://andrescolubri.net/androidbook/chapter-3/index.html

Go to the section: Preparing sketch for release



Thank you i’m going to look.


I am a beginner in programming and I still can not understand how to do it.
if anyone has any other advice I am a taker.


If you follow the link above, it says you need to use displayDensity():

void setup() {

void draw() {
  float r = 50 * displayDensity;   //  <------ This ensures this value is independent on screen specifications
  int maxi = int(width/r);
  int maxj = int(height/r);
  for (int i = 0; i <= maxi; i++) {
    float x = map(i, 0, maxi, 0, width);
    for (int j = 0; j <= maxj; j++) {
      float y = map(j, 0, maxj, 0, height);
      ellipse(x, y, r, r);

I do not have much experience with this topic, but I believe this is the way to do it. Give it a try and tell us if it works for you, or if it doesn’t.



The example works but I can not adapt it to my initial code.


I do not know too much, but I think the problem does not come from the dpi but rather a problem of compatibility between the screen ratio (16 / 9,18 / 9,4 / 3).