Aller au contenu
View in the app

A better way to browse. Learn more.

Forum de Frandroid

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Paramétrage d'un Paint pour dessiner des points dans un Canvas

Featured Replies

Posté(e)

Bonjour à tous,

Pour faire des essais de développement sur Android je veux faire un petit soft qui permette d'explorer l'ensemble de Mandelbrot.

Quand je dessine les points, sur l'écran de mon HTC Desire, je vois les pixels (genre ça fait un quadrillage et c'est pas beau). Comment faire pour avoir une jolie image ???

Fonction onDraw de la View

       @Override
       protected void onDraw(Canvas canvas) {
           Paint paint = mPaint;
           float[] mPts = new float[2];

           // canvas.translate(10, 10);

           canvas.drawColor(Color.BLACK);
           paint.setAntiAlias(true);
           paint.setStyle(Paint.Style.FILL_AND_STROKE);
           paint.setStrokeWidth(1);
           int h = canvas.getHeight();
           int w = canvas.getWidth();
           // paint.setColor(Color.RED);
           // paint.setStrokeWidth(0);

           // paint.setStrokeWidth(3);
           float a = -1.5f;
           float b;
           float step = 0.6f / w;
           for (int y = 0; y < h; y++) {
               b = -0.5f;
               for (int x = 0; x < w; x++) {
                   mPts[0] = x;
                   mPts[1] = y;
                   int loop = 0;
                   float z = 0.0f;
                   float xn = 0.0f;
                   float yn = 0.0f;
                   float xn1 = 0.0f;
                   float yn1 = 0.0f;
                   while ((loop < 30) && (z < 4.0f)) {
                       xn1 = xn * xn - yn * yn + a;
                       yn1 = 2 * xn * yn + b;
                       z = xn1 * xn1 + yn1 * yn1;
                       xn = xn1;
                       yn = yn1;
                       loop = loop + 1;
                   }
                   if (z < 4.0f) {
                       paint.setColor(Color.BLACK);
                       canvas.drawPoints(mPts, paint);
                   } else {
                       paint.setColor(Color.rgb(255, 15+8*loop, 0));
                       canvas.drawPoints(mPts, paint);
                   }
                   b = b + step;
               }
               a = a + step;
           }
       }
   }

Archivé

Ce sujet est désormais archivé et ne peut plus recevoir de nouvelles réponses.

Account

Navigation

Rechercher

Rechercher

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.