onDraw() triggered but results don't show

Posted by Don on Stack Overflow See other posts from Stack Overflow or by Don
Published on 2010-03-11T02:00:40Z Indexed on 2010/03/12 12:37 UTC
Read the original article Hit count: 206

Filed under:
|

I have the following routine in a subclass of view:

It calculates an array of points that make up a line, then erases the previous lines, then draws the new lines (impact refers to the width in pixels drawn with multiple lines). The line is your basic bell curve, squeezed or stretched by variance and x-factor.

Unfortunately, nothing shows on the screen. A previous version with drawPoint() and no array worked, and I've verified the array contents are being loaded correctly, and I can see that my onDraw() is being triggered.

Any ideas why it might not be drawn? Thanks in advance!

 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);
   y = Math.round(cy * root * ePow);
   points[index][1] = points[index][0];
   points[index][0] = (float) (maxy - y - OFFSET);

   index++;
  }
  points[maxx<<1][0] = (float) impact;

  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); // draw over old lines w/blk
  } 

  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);
   canvas.drawLines(pointsToPaint, myLinePaint); / new color
  }

 }

update: Replaced the drawLines() with drawPoint() in loop, still no joy

    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);

© Stack Overflow or respective owner

Related posts about android

Related posts about drawing