1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
| private fun drawPlanet(canvas: Canvas , index : Float) { val srcB = makeSrc(index) val dstB = makeDst(index)
val paint = Paint() canvas.saveLayer(-baseR, -baseR, baseR , baseR, null, Canvas.ALL_SAVE_FLAG) canvas.drawBitmap(dstB, -baseR / 2F, -baseR / 2F , paint) paint.xfermode = PorterDuffXfermode(PorterDuff.Mode.SRC_IN) canvas.drawBitmap(srcB, width / -2F, height / -2F , paint) paint.xfermode = null }
fun makeSrc(index :Float): Bitmap { val bm = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888) val canvas = Canvas(bm) canvas.translate(width.toFloat() / 2F , height.toFloat() / 2F)
val paint = Paint() paint.color = 0xff57BEC6.toInt() paint.style = Paint.Style.FILL
val rectf = RectF(-baseR / 2F, -baseR / 2F, baseR / 2F, baseR / 2F) canvas.drawArc(rectf , 0F , 360F , true , paint)
canvas.save()
paint.color = 0xff78D7DE.toInt() var baseR = baseR * 0.9.toFloat() val rectf2 = RectF(-baseR / 2F, -baseR / 2F, baseR / 2F, baseR / 2F) canvas.translate(baseR / 6F , baseR / 6F) canvas.drawArc(rectf2 , 0F , 360F , true , paint)
canvas.restore() canvas.rotate(-45F) canvas.save()
val bottomBaseR = baseR / 0.9F / 2 val path = Path() path.moveTo(-bottomBaseR , 0F) path.cubicTo(-bottomBaseR , bottomBaseR * 2, bottomBaseR , bottomBaseR * 2, bottomBaseR , 0F)
path.cubicTo( bottomBaseR * C,bottomBaseR , -bottomBaseR * C,bottomBaseR , -bottomBaseR , 0F )
paint.color = 0xffAAEEF2.toInt() paint.style = Paint.Style.FILL canvas.drawPath(path , paint)
drawPoints(index , canvas)
canvas.restore()
paint.strokeWidth = 30F paint.color = 0xff2F3768.toInt() paint.style = Paint.Style.STROKE canvas.drawArc(rectf , 0F , 360F , true , paint)
return bm }
private fun drawPoints(index: Float, canvas: Canvas) { val paintB = Paint() val paintS = Paint() paintS.style = Paint.Style.FILL paintS.color = 0xffE7F2FB.toInt()
paintB.style = Paint.Style.FILL paintB.color = 0xff2F3768.toInt()
val baseRB = baseR / 2F / 3 val baseRS = baseR / 2F / 3 / 3
val rectfB = RectF(-baseRB, -baseRB, baseRB, baseRB) val rectfS = RectF(-baseRS, -baseRS, baseRS, baseRS)
val pointPaint = Paint() pointPaint.color = Color.BLACK pointPaint.strokeWidth = 50F
val coverWidth = baseR
canvas.translate(-coverWidth / 2F , coverWidth * 1.5F)
val index = index canvas.translate(0F , coverWidth * index )
for (i in 0..2){ canvas.save() canvas.translate(coverWidth / 3F / 2 , -coverWidth / 3F * 2) canvas.drawArc(rectfB , 0F , 360F , true , paintB) canvas.drawArc(rectfS , 0F , 360F , true , paintS) canvas.restore()
canvas.save() canvas.translate(coverWidth / 3F *2 , -coverWidth / 3F) canvas.drawArc(rectfB , 0F , 360F , true , paintB) canvas.drawArc(rectfS , 0F , 360F , true , paintS) canvas.restore()
canvas.save() canvas.translate(coverWidth / 3F *2 , -coverWidth / 8F * 7 + -coverWidth / 10F ) canvas.drawArc(rectfS , 0F , 360F , true , paintB) canvas.restore()
canvas.save() canvas.translate(coverWidth / 3F *2 , -coverWidth / 8F * 7 - -coverWidth / 10F ) canvas.drawArc(rectfS , 0F , 360F , true , paintB) canvas.restore()
canvas.translate(0F , -coverWidth) } }
|