The following routine in a subclass of view attempts to draw a bell
curve on a canvas and display it.
It calculates an array of points, erases the previous pass, and then
draws a new set of lines. Tried with both drawLines() and drawPoint()
in a loop; no joy. Basic code worked when done in onDraw() as static
line draw, but doesn't cause drawing to appear in this iteration even
though onDraw is firing after lines are drawn.

Is there something I need to put in onDraw() as well? Tnx in advance!

<code><pre>
        @Override
        protected void onDraw(Canvas canvas) {
                height = getMeasuredHeight();
                width = getMeasuredWidth();
                canvasImpact = canvas;
                Log.i(DEBUG_TAG, "onDraw()");

        }

        protected void drawNewLine( int maxx, int maxy, Canvas canvas, int
impact, double variance,  double xFactor, int color) {
                // impact = 2 to 8; xFactor between 4 and 20; variance between 
0.2
and 5
                double x = 0;
                double y = 0;
                int cx = maxx / 2;
                int cy = maxy / 2;
                int mu = cx;
                int index = 0;
                points[maxx<<1][1] = points[maxx<<1][0];
                for (x = 0; x < maxx; x++) {
                        points[index][1] = points[index][0];
                        points[index][0] = (float) x;
//                      Log.i(DEBUG_TAG, "x: " + x);
                        index++;
                        double root = 1.0 / (Math.sqrt(2 * Math.PI * variance));
                        double exponent = -1.0 * (Math.pow(((x - 
mu)/maxx*xFactor), 2) / (2
* variance));
                        double ePow = Math.exp(exponent);
//                      Log.i(DEBUG_TAG, "root: " + root + " exp: " + exponent 
+ " ePow:
" + ePow);
                        y = Math.round(cy * root * ePow);
                        points[index][1] = points[index][0];
                        points[index][0] = (float) (maxy - y - OFFSET);

//                      Log.i(DEBUG_TAG, "y:          " + y);
                        index++;
                }
                points[maxx<<1][0] = (float) impact;
//              Log.i(DEBUG_TAG, "New impact");
//              Log.i(DEBUG_TAG, "Old impact: " + points[maxx<<1][1]);

                for (int line = 0; line < points[maxx<<1][1]; line++) {
                        for (int pt = 0; pt < (maxx<<1); pt++) {
                                pointsToPaint[pt] = points[pt][1];
                        }
                        for (int skip = 1; skip < (maxx<<1); skip = skip + 2)
pointsToPaint[skip] = pointsToPaint[skip] + line;
                        myLinePaint.setColor(Color.BLACK);
                        canvas.drawLines(pointsToPaint, bLinePaint);
                }

                for (int line = 0; line < points[maxx<<1][0]; line++) {
                        for (int pt = 0; pt < maxx<<1; pt++) {
                                pointsToPaint[pt] = points[pt][0];
                        }
                        for (int skip = 1; skip < maxx<<1; skip = skip + 2)
pointsToPaint[skip] = pointsToPaint[skip] + line;
                        myLinePaint.setColor(color);
                        for (int p = 0; p<pointsToPaint.length; p = p + 2) {
                                Log.i(DEBUG_TAG, "x " + pointsToPaint[p] + " y 
" + pointsToPaint[p
+1]);
                                canvas.drawPoint(pointsToPaint[p], 
pointsToPaint[p+1],
myLinePaint);
                        }
///                     canvas.drawLines(pointsToPaint, myLinePaint);
                }

        }
</pre>  </code>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to