Refresh the screen while drawing on the canvas

Problems with Canvas, OpenGL, etc...

Refresh the screen while drawing on the canvas

Postby fabiofaccin » Wed Nov 09, 2011 7:02 pm

Hello, I would like to know how I could update the device's screen while the loop draws on the screen.

To improve understanding, I'm doing an application that calculates the Mandelbrot set. What is it?.

The calculations are done inside OnDraw method of application, but instead of to show the pictures as they are created, the picture appears only after the loops ends ... Such as the calculation takes a few seconds (depends on the configuration that use), the device's screen goes black and it appears that the application crashed.

The following the code of the OnDraw method:

Code: Select all
public void onDraw(Canvas c) {
            int j = -1;
            while (++j < c.getHeight()) {  //Loop for the lines
                int i = -1;
                while (++i < c.getWidth()) {      //Loop for the columns
                    float x = 0f;
                    float y = 0f;
                    int v = 0;
                    //Calculate the number of iterations
                    for (; v < iteracoes && (x * x + y * y) / 2f < 2f; v++) {
                        float t = i / zoom + (posicaox) + x * x - y * y;
                        y = j / zoom + (posicaoy) + x * y * 2f;
                        x = t;
                    }

                    //define a color to paint the screen
                    float blue = 0;
                    if (v == iteracoes) {
                        blue = 0;
                        p.setARGB(255, 0, 0, 0);
                    } else {
                        blue = 255 / iteracoes;
                        blue = blue * v * 3 + 50;
                        if (v < 50) {
                            p.setARGB(255, 0, 0, (int) (blue));
                        } else {
                            p.setARGB(255, 100, 150, (int) (blue));
                        }

                    }
                    //paints the screen with a "pixel"
                    c.drawRect(i, j, i + 1, j + 1, p);

                }
            //HERE I WANT TO VIEW THE LINE THAT THE APPLICATION HAS GENERATED ON SCREEN GIVING IDEA THAT THE APPLICATION IS REALLY WORKING
            }
        }
    }
}


Thank you for your attention! :)

Sorry for my English! :(
fabiofaccin
Once Poster
Once Poster
 
Posts: 1
Joined: Wed Nov 09, 2011 6:30 pm

Top

Return to Android 2D/3D Graphics - OpenGL Problems

Who is online

Users browsing this forum: No registered users and 4 guests