Created
August 16, 2017 06:40
-
-
Save bigstark/7c3515b15deae2a391ea82694615d8cb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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