java - Attempting to draw a grid in Android using drawRect getting strange output -
i'm attempting draw grid of rectangle objects game of life application. @ stage im trying base grid work. evaluate boolean array live , dead cells , change paint style accordingly. i've simplified code as can testing purposes. im attempting draw 9x6 grid of 100x100 rectangles no padding.
here code:
paintgrid.setstyle(paint.style.stroke); //sets paint style grid squares int gm = 100; //gridmultiplier determines rectangle size in case 100x100 for(int r = 0; r < 9; r++) //paints grid 9 rows { for(int c = 0; c < grid[0].length; c++) //6 columns { top = r*gm; //sets left side bottom = top+gm; //sets right side left = c*gm; right = left+gm; log.v(logtag, "left: " + left + " right: "+ right+ " top: " + top + " bottom: " + bottom); //testing canvas.drawrect(left, top, bottom, right, paintgrid); //paints dead cell } }
i expect draw grid first drawing top row left right, second row, , continue until complete. instead output.
the logcat output im using testing seem indicate loop working properly. get: left: 0 right 100 top 0 bottom 100 left: 100 right 200 top 0 bottom 100 left: 200 right 300 top 0 bottom 100 left: 300 right 400 top 0 bottom 100 left: 400 right 500 top 0 bottom 100
left 0 right 100 top 100 bottom 200 left 100 right 200 top 100 bottom 200 left 200 right 300 top 100 bottom 200 ... etc
im @ wits ends here! under impression 2d arrays row major ive been trying keep setup. suggestions? in advance!
you have switched right , bottom arguments. right order left, top, right, bottom. result produced since android needs right > left , bottom > top or wont draw rectangle @ all. code draws ones in diagonal isn't relevant due bottom = right.
Comments
Post a Comment