Note that there are some explanatory texts on larger screens.

plurals
  1. POonDraw() triggered but results don't show
    text
    copied!<p>I have the following routine in a subclass of view:</p> <p>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.</p> <p>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. </p> <p>Any ideas why it might not be drawn? Thanks in advance! </p> <pre><code> 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&lt;&lt;1][1] = points[maxx&lt;&lt;1][0]; for (x = 0; x &lt; 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&lt;&lt;1][0] = (float) impact; for (int line = 0; line &lt; points[maxx&lt;&lt;1][1]; line++) { for (int pt = 0; pt &lt; (maxx&lt;&lt;1); pt++) { pointsToPaint[pt] = points[pt][1]; } for (int skip = 1; skip &lt; (maxx&lt;&lt;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 &lt; points[maxx&lt;&lt;1][0]; line++) { for (int pt = 0; pt &lt; maxx&lt;&lt;1; pt++) { pointsToPaint[pt] = points[pt][0]; } for (int skip = 1; skip &lt; maxx&lt;&lt;1; skip = skip + 2) pointsToPaint[skip] = pointsToPaint[skip] + line; myLinePaint.setColor(color); canvas.drawLines(pointsToPaint, myLinePaint); / new color } } </code></pre> <p>update: Replaced the drawLines() with drawPoint() in loop, still no joy<br /></p> <pre><code> for (int p = 0; p&lt;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); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload