android Paint 特效繪圖收集

//心形 https://www.jianshu.com/p/69819295a0ef?nomobile=yes
int i, j;
double x, y, r;

for (i = 0; i <= 90; i++) {
    for (j = 0; j <= 90; j++) {
        r = Math.PI / 45 * i * (1 - Math.sin(Math.PI / 45 * j)) * 20;
        x = r * Math.cos(Math.PI / 45 * j) * Math.sin(Math.PI / 45 * i) + 320 / 2;
        y = -r * Math.sin(Math.PI / 45 * j) + 400 / 4;
        canvas.drawPoint((float) x, (float) y, paint);
    }
}
2.https://www.jianshu.com/p/0edabe6ce8c9  PorterDuffXfermode
    int x = 0;
    //繪製梯形能量條 
    @Override
    protected void onDraw(final Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawColor(Color.WHITE);
        Bitmap bitmap2 = BitmapFactory.decodeResource(getResources(), R.drawable.x8_top_view);//獲取 bitmap 資源
        canvas.drawBitmap(bitmap2, getWidth() / 2 - bitmap2.getWidth() / 2, getHeight() / 2 - bitmap2.getHeight() / 2, null);//繪製 bitmap
        final int sc = canvas.saveLayer(0, 0, getWidth(), getHeight(), null, Canvas.ALL_SAVE_FLAG);
        Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.x8_top_power);//獲取 bitmap 資源
        canvas.drawBitmap(bitmap, getWidth() / 2 - bitmap.getWidth() / 2, getHeight() / 2 - bitmap.getHeight() / 2, null);//繪製 bitmap

        mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OUT));//設置特效畫筆
        mPaint.setColor(Color.parseColor("#00000000"));//
        //canvas.rotate(45, getWidth() / 2, getHeight() / 2);
        int left = getWidth() / 2 - bitmap.getWidth() / 2;
        int top = getHeight() / 2 - bitmap.getHeight() / 2;

        canvas.drawRect(left + bitmap.getWidth() - x, top, left + bitmap.getWidth(), top + bitmap.getHeight(), mPaint);//最後將畫筆去除Xfermode
        mPaint.setXfermode(null);
        canvas.restoreToCount(sc);// 還原畫布
        if (x >= bitmap.getWidth()) {
            x = 0;
        }
        x = x + 2;
        postInvalidateDelayed(20);
    }
   
3.水紋進度(貝塞爾曲線)---瓶子
https://github.com/GuoFeilong/ATLoading

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章