Skip to content

Instantly share code, notes, and snippets.

@bigstark
Created August 16, 2017 06:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bigstark/7c3515b15deae2a391ea82694615d8cb to your computer and use it in GitHub Desktop.
Save bigstark/7c3515b15deae2a391ea82694615d8cb to your computer and use it in GitHub Desktop.
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
int width = getWidth();
int height = getHeight();
float size = (width > height ? height : width) - tileMargin * 2;
float tileSize = size / 3;
// draw tiles except from and to
for (int[] tile : TILES) {
if ((tile[0] == from[0] && tile[1] == from[1]) ||
(tile[0] == to[0] && tile[1] == to[1])) {
continue;
}
float left = tile[0] * (tileSize + tileMargin);
float top = tile[1] * (tileSize + tileMargin);
canvas.drawRect(left, top, left + tileSize, top + tileSize, paint);
}
// draw from
float fromLeft = (from[0] + (to[0] - from[0]) * frame) * (tileSize + tileMargin);
float fromTop = (from[1] + (to[1] - from[1]) * frame) * (tileSize + tileMargin);
canvas.drawRect(fromLeft, fromTop, fromLeft + tileSize, fromTop + tileSize, paint);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment