Android processing bug

edited April 20 in Android Mode

Hello I'm trying to make an animated wallpaper for my phone, but when I rotate the screen, the sketck gets distorted and out of the screen space.

I think this is a bug, but I want to know how to wrkarround that so my sketch work correctly.

I am using the lastest version of the android processing library, android 4.4.2.

This is when I do not rotate the screen: Normal

This is when I rotate the screen: Rotated

This is the code:

int precision = 10;

float[] senos = new float[360 * precision];
float[] cosenos = new float[360 * precision];

float[] velocidad = new float[2];
float aceleracion;

void setup() {
  fullScreen(P2D);
  smooth(8);

  stroke(255);
  fill(255);

  senos = calcularSenos(senos);
  cosenos = calcularCosenos(cosenos);

  for (int i = 0; i < velocidad.length; i++) {
    velocidad[i] = random(1, 2);
  }
}

void draw() {
  background(0);

  linea(width / 2, height, 180, height / 3);
  aceleracion += .1;
}

float[] calcularSenos(float[] a) {
  for (int i = 0; i < a.length; i++) {
    a[i] = sin(radians((float)i * 360 / a.length));
  }

  return a;
}

float[] calcularCosenos(float[] a) {
  for (int i = 0; i < a.length; i++) {
    a[i] = cos(radians((float)i * 360 / a.length));
  }

  return a;
}

void linea(float principioX, float principioY, float angulo, float longitud) {
  if (longitud >= 1) {
    float finalX;
    float finalY;

    if (angulo >= 0) {
      finalX = senos[(int)abs(angulo * precision % (360 * precision))] * longitud + principioX;
      finalY = cosenos[(int)abs(angulo * precision % (360 * precision))] * longitud + principioY;
    } else {
      finalX = -senos[(int)abs(angulo * precision % (360 * precision))] * longitud + principioX;
      finalY = cosenos[(int)abs(angulo * precision % (360 * precision))] * longitud + principioY;
    }

    line(principioX, principioY, finalX, finalY);

    linea(finalX, finalY, angulo + velocidad[0] * aceleracion, longitud / 1.5);
    linea(finalX, finalY, angulo - velocidad[1] * aceleracion, longitud / 1.5);
  }
}
Tagged:

Answers

Sign In or Register to comment.