Java started learning two or three days ago, but worked with Canvas in javascript.
You now have about the following algorithm:
цикл { нарисовать ячейку (клетку) }
Why don't you create a class: CanvasCell , with methods
PS syntax problems may be
public class CanvasCell { public int x; public int y; public int width; // может быть и вещественным public int height; public boolean isChange = false; // изменилась ли наша ячейка public void draw() { /* контекст Canvas можно передавать в параметрах в этой ф-ции, используя поля, рисуем клетку */ } /* конструктор */ public CanvasCell(int x, int y, int width, int height) { /* тут присваиваем значения */ } } А потом создаем наши экземпляры СanvasCell[] cells = []; // наш массив ячеек;
Where is the optimization , you ask?
The optimization is that during the next rendering we will draw only those cells that have changed, check on the isChange field. The instance will store all the necessary information (coordinates, size, and so on) so it will not be difficult to redraw + this can be easily scaled later (add a new property).
Total : the idea is to have access to each object on the Canvas, then you can simulate layers, using the OOP is perfect here
PS Unfortunately, the implementation itself, I can not write, is not yet familiar with the whole java (