Skip to content

Commit

Permalink
finish practiceDraw4
Browse files Browse the repository at this point in the history
  • Loading branch information
CrazyPudding committed May 22, 2018
1 parent 673e9ff commit 225739f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,28 @@ protected void onDraw(Canvas canvas) {

float centerX1 = point1.x + bitmap.getWidth() / 2;
float centerY1 = point1.y + bitmap.getHeight() / 2;
float centerX2 = point2.y + bitmap.getHeight() / 2;
float centerX2 = point2.x + bitmap.getHeight() / 2;
float centerY2 = point2.y + bitmap.getHeight() / 2;

canvas.save();
camera.save();
matrix.reset();
matrix.postTranslate(-centerX1, -centerY1);
camera.rotateX(30);
canvas.translate(centerX1, centerY1);
camera.applyToCanvas(canvas);
canvas.translate(-centerX1, -centerY1);
camera.restore();
canvas.drawBitmap(bitmap, point1.x, point1.y, paint);
canvas.restore();

canvas.save();
matrix.reset();
camera.save();
camera.rotateY(30);
camera.applyToCanvas(canvas);
camera.getMatrix(matrix);
camera.restore();
matrix.postTranslate(centerX2, centerY2);
matrix.preTranslate(-centerX2, -centerY2);
canvas.concat(matrix);
canvas.drawBitmap(bitmap, point2.x, point2.y, paint);
canvas.restore();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,17 @@ protected void onDraw(Canvas canvas) {
int y = centerY - bitmapHeight / 2;

canvas.save();
canvas.clipRect(0, 0, getWidth(), centerY);
canvas.drawBitmap(bitmap, x, y, paint);
canvas.restore();

canvas.save();
camera.save();
camera.rotateX(degree);
canvas.translate(centerX, centerY);
camera.applyToCanvas(canvas);
canvas.translate(-centerX, -centerY);
canvas.clipRect(0, centerY, getWidth(), getHeight());
camera.restore();

canvas.drawBitmap(bitmap, x, y, paint);
Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,11 @@ fork 自 [HenCoder](https://github.com/hencoder) 的练习题集合,学习自
原项目 [README](/PracticeDraw3/README.md)

完成效果:
![](/images/practice2.jpg)
![](/images/practice2.jpg)

## 4.Canvas绘制辅助

原项目 [READE](/PracticeDraw4/README.md)

完成效果:
![](/images/practice4.jpg)
Binary file added images/practice4.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 225739f

Please sign in to comment.