Share
Embed
Canvas Drawing
Introduction to 2D drawing on Android using the Canvas API from #droidconSF.
Ryan Harter
November 05, 2017
Annual Pro sale · Save $30
Have presentations of your own?
Share with private links, password protection, and more control over your work.
Transcript
104 slides
-
How To Get A Canvas class CustomView(...) : View(...) {
override fun onDraw(canvas: Canvas?) { } } -
How To Get A Canvas class CustomView(...) : View(...) {
override fun onDraw(canvas: Canvas?) { } } class CustomDrawable : Drawable() { override fun draw(canvas: Canvas?) { } } -
How To Get A Canvas class CustomView(...) : View(...) {
override fun onDraw(canvas: Canvas?) { } } class CustomDrawable : Drawable() { override fun draw(canvas: Canvas?) { } } val image = Bitmap.createBitmap(100, 100, ARGB_8888) val canvas = Canvas(image) -
How To Get A Canvas class CustomView(...) : View(...) {
override fun onDraw(canvas: Canvas?) { } } class CustomDrawable : Drawable() { override fun draw(canvas: Canvas?) { } } val image = Bitmap.createBitmap(100, 100, ARGB_8888) val canvas = Canvas(image) -
private val basePaint = Paint().apply { color = 0xFFc6853b.toInt() }\
canvas.drawCircle( bounds.exactCenterX(), // center x bounds.exactCenterY(), // center y bounds.width() / 2f, // radius basePaint) private val basePaint = Paint().apply { color = 0xFFc6853b.toInt() }\ canvas.drawCircle( bounds.exactCenterX(), // center x bounds.exactCenterY(), // center y bounds.width() / 2f, // radius basePaint) Canvas Drawing -
private val basePaint = Paint().apply { color = 0xFFc6853b.toInt() }\
canvas.drawCircle( bounds.exactCenterX(), // center x bounds.exactCenterY(), // center y bounds.width() / 2f, // radius basePaint) private val basePaint = Paint().apply { color = 0xFFc6853b.toInt() }\ canvas.drawCircle( bounds.exactCenterX(), // center x bounds.exactCenterY(), // center y bounds.width() / 2f, // radius basePaint) Canvas Drawing -
private val basePaint = Paint().apply { color = 0xFFc6853b.toInt() }\
canvas.drawCircle( bounds.exactCenterX(), // center x bounds.exactCenterY(), // center y bounds.width() / 2f, // radius basePaint) private val basePaint = Paint().apply { color = 0xFFc6853b.toInt() }\ canvas.drawCircle( bounds.exactCenterX(), // center x bounds.exactCenterY(), // center y bounds.width() / 2f, // radius basePaint) Canvas Drawing -
private val basePaint = Paint().apply { color = 0xFFc6853b.toInt() }\
canvas.drawCircle( bounds.exactCenterX(), // center x bounds.exactCenterY(), // center y bounds.width() / 2f, // radius basePaint) private val basePaint = Paint().apply { color = 0xFFc6853b.toInt() }\ canvas.drawCircle( bounds.exactCenterX(), // center x bounds.exactCenterY(), // center y bounds.width() / 2f, // radius basePaint) Canvas Drawing what -
private val basePaint = Paint().apply { color = 0xFFc6853b.toInt() }\
canvas.drawCircle( bounds.exactCenterX(), // center x bounds.exactCenterY(), // center y bounds.width() / 2f, // radius basePaint) private val basePaint = Paint().apply { color = 0xFFc6853b.toInt() }\ canvas.drawCircle( bounds.exactCenterX(), // center x bounds.exactCenterY(), // center y bounds.width() / 2f, // radius basePaint) Canvas Drawing what how -
private val basePaint = Paint().apply { color = 0xFFc6853b.toInt() }\
canvas.drawCircle( bounds.exactCenterX(), // center x bounds.exactCenterY(), // center y bounds.width() / 2f, // radius basePaint) private val basePaint = Paint().apply { color = 0xFFc6853b.toInt() }\ canvas.drawCircle( bounds.exactCenterX(), // center x bounds.exactCenterY(), // center y bounds.width() / 2f, // radius basePaint) Canvas Drawing -
private val basePaint = Paint().apply { color = 0xFFc6853b.toInt() }\
canvas.drawCircle( bounds.exactCenterX(), // center x bounds.exactCenterY(), // center y bounds.width() / 2f, // radius basePaint) private val basePaint = Paint().apply { color = 0xFFc6853b.toInt() }\ canvas.drawCircle( bounds.exactCenterX(), // center x bounds.exactCenterY(), // center y bounds.width() / 2f, // radius basePaint) Canvas Drawing -
private val basePaint = Paint().apply { color = 0xFFc6853b.toInt() }\
canvas.drawCircle( bounds.exactCenterX(), // center x bounds.exactCenterY(), // center y bounds.width() / 2f, // radius basePaint) private val basePaint = Paint().apply { color = 0xFFc6853b.toInt() }\ canvas.drawCircle( bounds.exactCenterX(), // center x bounds.exactCenterY(), // center y bounds.width() / 2f, // radius basePaint) Canvas Drawing -
private val basePaint = Paint().also { it.color = 0xFFc6853b.toInt() }\
canvas.drawCircle( bounds.exactCenterX(), // center x bounds.exactCenterY(), // center y bounds.width() / 2f, // radius basePaint) Canvas Drawing private val basePaint = Paint().also { it.color = 0xFFc6853b.toInt() }\ canvas.drawCircle( bounds.exactCenterX(), // center x bounds.exactCenterY(), // center y bounds.width() / 2f, // radius basePaint) // draw the base -
fun onBoundsChange(bounds: Rect?) { super.onBoundsChange(bounds) bounds?.let { holePath.reset() holePath.addCircle( it.exactCenterX(),
it.exactCenterY(), it.width() / 6F, Path.Direction.CW) }\ }\ fun onBoundsChange(bounds: Rect?) { super.onBoundsChange(bounds) bounds?.let { holePath.reset() holePath.addCircle( it.exactCenterX(), it.exactCenterY(), it.width() / 6F, Path.Direction.CW) }\ }\ Canvas Drawing canvas.clipPath(holePath, canvas.clipPath(holePath, private val holePath = Path() private val holePath = Path() -
fun onBoundsChange(bounds: Rect?) { super.onBoundsChange(bounds) bounds?.let { holePath.reset() holePath.addCircle( it.exactCenterX(),
it.exactCenterY(), it.width() / 6F, Path.Direction.CW) }\ }\ fun onBoundsChange(bounds: Rect?) { super.onBoundsChange(bounds) bounds?.let { holePath.reset() holePath.addCircle( it.exactCenterX(), it.exactCenterY(), it.width() / 6F, Path.Direction.CW) }\ }\ Canvas Drawing canvas.clipPath(holePath, canvas.clipPath(holePath, private val holePath = Path() private val holePath = Path() -
// draw the base Canvas Drawing canvas.clipPath(holePath, Region.Op.DIFFERENCE) canvas.clipPath(holePath, Region.Op.DIFFERENCE)
// draw the stache canvas.save() canvas.restore() canvas.save() canvas.restore() // draw the base // draw the stache -
// draw the base Canvas Drawing canvas.clipPath(holePath, Region.Op.DIFFERENCE) canvas.clipPath(holePath, Region.Op.DIFFERENCE)
// draw the stache canvas.save() canvas.restore() canvas.save() canvas.restore() // draw the base // draw the stache -
// draw the base Canvas Drawing canvas.clipPath(holePath, Region.Op.DIFFERENCE) canvas.clipPath(holePath, Region.Op.DIFFERENCE)
canvas.save() canvas.restore() canvas.save() canvas.restore() // draw the base -
// clip the hole // Clip the hole // draw
the base Canvas Drawing // draw the base -
// draw the icing // draw the icing // clip
the hole // Clip the hole // draw the base Canvas Drawing // draw the base -
// draw the icing // draw the icing // clip
the hole // Clip the hole // draw the base Canvas Drawing // draw the base -
// draw the icing // draw the icing // clip
the hole // Clip the hole // draw the base Canvas Drawing // draw the base DiscretePathEffect(60f, 25f) DiscretePathEffect(60f, 25f) -
// draw the icing // draw the icing // clip
the hole // Clip the hole // draw the base Canvas Drawing // draw the base DiscretePathEffect(60f, 25f) DiscretePathEffect(60f, 25f) -
// draw the icing // draw the icing // clip
the hole // Clip the hole // draw the base Canvas Drawing // draw the base DiscretePathEffect(60f, 25f) DiscretePathEffect(60f, 25f) -
// draw the icing // draw the icing // clip
the hole // Clip the hole // draw the base Canvas Drawing // draw the base DiscretePathEffect(60f, 25f) DiscretePathEffect(60f, 25f) -
// draw the icing // draw the icing // clip
the hole // Clip the hole // draw the base Canvas Drawing // draw the base DiscretePathEffect(60f, 25f) DiscretePathEffect(60f, 25f) -
// draw the icing // draw the icing // clip
the hole // Clip the hole // draw the base Canvas Drawing // draw the base DiscretePathEffect(60f, 25f) DiscretePathEffect(60f, 25f) CornerPathEffect(40f) CornerPathEffect(40f) -
// draw the icing // draw the icing // clip
the hole // Clip the hole // draw the base Canvas Drawing // draw the base DiscretePathEffect(60f, 25f) DiscretePathEffect(60f, 25f) CornerPathEffect(40f) CornerPathEffect(40f) -
, // draw the icing // draw the icing //
clip the hole // Clip the hole // draw the base Canvas Drawing // draw the base DiscretePathEffect(60f, 25f) DiscretePathEffect(60f, 25f) CornerPathEffect(40f) CornerPathEffect(40f) ComposePathEffect( ComposePathEffect( ) ) , -
, // draw the icing // draw the icing //
clip the hole // Clip the hole // draw the base Canvas Drawing // draw the base DiscretePathEffect(60f, 25f) DiscretePathEffect(60f, 25f) CornerPathEffect(40f) CornerPathEffect(40f) ComposePathEffect( ComposePathEffect( ) ) , -
// draw the icing // draw the icing // clip
the hole // Clip the hole // draw the base Canvas Drawing // draw the base ComposePathEffect( ComposePathEffect() ) -
// draw the icing // draw the icing // clip
the hole // Clip the hole // draw the base Canvas Drawing // draw the base ComposePathEffect( ComposePathEffect() ) canvas.drawCircle( bounds.exactCenterX(), bounds.exactCenterY(), bounds.width() / 2.1f, icingPaint) -
// draw the icing // draw the icing // clip
the hole // Clip the hole // draw the base Canvas Drawing // draw the base ComposePathEffect( ComposePathEffect() ) canvas.drawCircle( bounds.exactCenterX(), bounds.exactCenterY(), bounds.width() / 2.1f, icingPaint) -
Canvas Drawing // draw the icing // draw the icing
// clip the hole // Clip the hole // draw the base // draw the base -
Canvas Drawing // draw the sprinkles! // draw the icing
// draw the icing // clip the hole // Clip the hole // draw the base // draw the base // draw the sprinkles! -
// draw the sprinkles! // draw the sprinkles! Canvas Drawing
sprinkles.forEach { sprinkles.forEach { } } -
// draw the sprinkles! // draw the sprinkles! Canvas Drawing
sprinkles.forEach { sprinkles.forEach { // calculate the position // calculate the position } } -
// draw the sprinkles! // draw the sprinkles! Canvas Drawing
sprinkles.forEach { sprinkles.forEach { // move the canvas // move the canvas // calculate the position // calculate the position } } -
// draw the sprinkles! // draw the sprinkles! Canvas Drawing
sprinkles.forEach { sprinkles.forEach { // move the canvas // move the canvas // draw the sprinkle // draw the sprinkle // calculate the position // calculate the position } } -
// draw the sprinkles! // draw the sprinkles! Canvas Drawing
sprinkles.forEach { sprinkles.forEach { // move the canvas // move the canvas // draw the sprinkle // draw the sprinkle // restore the canvas // restore the canvas // calculate the position // calculate the position } } -
// draw the sprinkles! // draw the sprinkles! Canvas Drawing
sprinkles.forEach { sprinkles.forEach { // move the canvas // move the canvas // draw the sprinkle // draw the sprinkle // restore the canvas // restore the canvas val modDistance = holeRadius + padding + (ringRadius - padding * 2) * it.distance // calculate the position // calculate the position } } -
// draw the sprinkles! // draw the sprinkles! Canvas Drawing
sprinkles.forEach { sprinkles.forEach { // calculate the position // calculate the position // move the canvas // move the canvas // draw the sprinkle // draw the sprinkle // restore the canvas // restore the canvas val modDistance = holeRadius + padding + (ringRadius - padding * 2) * it.distance canvas.save() canvas.rotate(it.angle, cx, cy) canvas.translate(0f, modDistance) canvas.rotate(it.rotation, cx, cy) canvas.save() canvas.rotate(it.angle, cx, cy) canvas.translate(0f, modDistance) canvas.rotate(it.rotation, cx, cy) } } -
// draw the sprinkles! // draw the sprinkles! Canvas Drawing
sprinkles.forEach { sprinkles.forEach { // calculate the position // draw the sprinkle // draw the sprinkle // restore the canvas // restore the canvas // calculate the position // calculate the position // move the canvas // move the canvas val modDistance = holeRadius + padding + (ringRadius - padding * 2) * it.distance canvas.save() canvas.rotate(it.angle, cx, cy) canvas.translate(0f, modDistance) canvas.rotate(it.rotation, cx, cy) canvas.save() canvas.rotate(it.angle, cx, cy) canvas.translate(0f, modDistance) canvas.rotate(it.rotation, cx, cy) } } -
// draw the sprinkles! // draw the sprinkles! Canvas Drawing
sprinkles.forEach { sprinkles.forEach { // draw the sprinkle // draw the sprinkle // restore the canvas // restore the canvas // calculate the position // calculate the position // move the canvas // move the canvas val modDistance = holeRadius + padding + (ringRadius - padding * 2) * it.distance canvas.save() canvas.rotate(it.angle, cx, cy) canvas.translate(0f, modDistance) canvas.rotate(it.rotation, cx, cy) canvas.save() canvas.rotate(it.angle, cx, cy) canvas.translate(0f, modDistance) canvas.rotate(it.rotation, cx, cy) } } -
// draw the sprinkles! // draw the sprinkles! Canvas Drawing
sprinkles.forEach { sprinkles.forEach { // draw the sprinkle // draw the sprinkle // restore the canvas // restore the canvas // calculate the position // calculate the position // move the canvas // move the canvas val modDistance = holeRadius + padding + (ringRadius - padding * 2) * it.distance canvas.save() canvas.rotate(it.angle, cx, cy) canvas.translate(0f, modDistance) canvas.rotate(it.rotation, cx, cy) canvas.save() canvas.rotate(it.angle, cx, cy) canvas.translate(0f, modDistance) canvas.rotate(it.rotation, cx, cy) } } -
// draw the sprinkles! // draw the sprinkles! Canvas Drawing
sprinkles.forEach { sprinkles.forEach { // draw the sprinkle // draw the sprinkle // restore the canvas // restore the canvas // calculate the position // calculate the position // move the canvas // move the canvas val modDistance = holeRadius + padding + (ringRadius - padding * 2) * it.distance canvas.save() canvas.rotate(it.angle, cx, cy) canvas.translate(0f, modDistance) canvas.rotate(it.rotation, cx, cy) canvas.save() canvas.rotate(it.angle, cx, cy) canvas.translate(0f, modDistance) canvas.rotate(it.rotation, cx, cy) } } -
// draw the sprinkles! // draw the sprinkles! Canvas Drawing
sprinkles.forEach { sprinkles.forEach { // draw the sprinkle // draw the sprinkle // restore the canvas // restore the canvas // calculate the position // calculate the position // move the canvas // move the canvas val modDistance = holeRadius + padding + (ringRadius - padding * 2) * it.distance canvas.save() canvas.rotate(it.angle, cx, cy) canvas.translate(0f, modDistance) canvas.rotate(it.rotation, cx, cy) canvas.save() canvas.rotate(it.angle, cx, cy) canvas.translate(0f, modDistance) canvas.rotate(it.rotation, cx, cy) } } -
// draw the sprinkles! // draw the sprinkles! Canvas Drawing
sprinkles.forEach { sprinkles.forEach { // draw the sprinkle // draw the sprinkle // restore the canvas // restore the canvas // calculate the position // calculate the position // move the canvas // move the canvas val modDistance = holeRadius + padding + (ringRadius - padding * 2) * it.distance canvas.save() canvas.rotate(it.angle, cx, cy) canvas.translate(0f, modDistance) canvas.rotate(it.rotation, cx, cy) canvas.save() canvas.rotate(it.angle, cx, cy) canvas.translate(0f, modDistance) canvas.rotate(it.rotation, cx, cy) } } -
// draw the sprinkles! // draw the sprinkles! Canvas Drawing
sprinkles.forEach { sprinkles.forEach { // draw the sprinkle // draw the sprinkle // restore the canvas // restore the canvas // calculate the position // calculate the position // move the canvas // move the canvas val modDistance = holeRadius + padding + (ringRadius - padding * 2) * it.distance canvas.save() canvas.rotate(it.angle, cx, cy) canvas.translate(0f, modDistance) canvas.rotate(it.rotation, cx, cy) canvas.save() canvas.rotate(it.angle, cx, cy) canvas.translate(0f, modDistance) canvas.rotate(it.rotation, cx, cy) } } -
// draw the sprinkles! // draw the sprinkles! Canvas Drawing
sprinkles.forEach { sprinkles.forEach { // draw the sprinkle // draw the sprinkle // restore the canvas // restore the canvas // calculate the position // calculate the position // move the canvas // move the canvas val modDistance = holeRadius + padding + (ringRadius - padding * 2) * it.distance canvas.save() canvas.rotate(it.angle, cx, cy) canvas.translate(0f, modDistance) canvas.rotate(it.rotation, cx, cy) canvas.save() canvas.rotate(it.angle, cx, cy) canvas.translate(0f, modDistance) canvas.rotate(it.rotation, cx, cy) } } -
// draw the sprinkles! // draw the sprinkles! Canvas Drawing
sprinkles.forEach { sprinkles.forEach { // draw the sprinkle // draw the sprinkle // restore the canvas // restore the canvas // calculate the position // calculate the position // move the canvas // move the canvas val modDistance = holeRadius + padding + (ringRadius - padding * 2) * it.distance canvas.save() canvas.rotate(it.angle, cx, cy) canvas.translate(0f, modDistance) canvas.rotate(it.rotation, cx, cy) canvas.save() canvas.rotate(it.angle, cx, cy) canvas.translate(0f, modDistance) canvas.rotate(it.rotation, cx, cy) } } -
// draw the sprinkles! // draw the sprinkles! Canvas Drawing
sprinkles.forEach { sprinkles.forEach { // draw the sprinkle // draw the sprinkle // restore the canvas // restore the canvas // calculate the position // calculate the position // move the canvas // move the canvas val modDistance = holeRadius + padding + (ringRadius - padding * 2) * it.distance canvas.save() canvas.rotate(it.angle, cx, cy) canvas.translate(0f, modDistance) canvas.rotate(it.rotation, cx, cy) canvas.save() canvas.rotate(it.angle, cx, cy) canvas.translate(0f, modDistance) canvas.rotate(it.rotation, cx, cy) sprinklePaint.color = it.color canvas.drawRoundRect( cx - 7f, cy - 22f, cx + 7f, cy + 22f, 10f, 10f, sprinklePaint) } } -
sprinklePaint.color = it.color canvas.drawRoundRect( cx - 7f, cy - 22f,
cx + 7f, cy + 22f, 10f, 10f, sprinklePaint) sprinklePaint.color = it.color canvas.drawRoundRect( cx - 7f, cy - 22f, cx + 7f, cy + 22f, 10f, 10f, sprinklePaint) // draw the sprinkles! // draw the sprinkles! Canvas Drawing sprinkles.forEach { sprinkles.forEach { } } // draw the sprinkle // draw the sprinkle // restore the canvas // restore the canvas // calculate the position // calculate the position // move the canvas // move the canvas val modDistance = holeRadius + padding + (ringRadius - padding * 2) * it.distance canvas.save() canvas.rotate(it.angle, cx, cy) canvas.translate(0f, modDistance) canvas.rotate(it.rotation, cx, cy) canvas.save() canvas.rotate(it.angle, cx, cy) canvas.translate(0f, modDistance) canvas.rotate(it.rotation, cx, cy) -
sprinklePaint.color = it.color canvas.drawRoundRect( cx - 7f, cy - 22f,
cx + 7f, cy + 22f, 10f, 10f, sprinklePaint) sprinklePaint.color = it.color canvas.drawRoundRect( cx - 7f, cy - 22f, cx + 7f, cy + 22f, 10f, 10f, sprinklePaint) // draw the sprinkles! // draw the sprinkles! Canvas Drawing sprinkles.forEach { sprinkles.forEach { // draw the sprinkle // draw the sprinkle // restore the canvas // restore the canvas // calculate the position // calculate the position // move the canvas // move the canvas val modDistance = holeRadius + padding + (ringRadius - padding * 2) * it.distance canvas.save() canvas.rotate(it.angle, cx, cy) canvas.translate(0f, modDistance) canvas.rotate(it.rotation, cx, cy) canvas.save() canvas.rotate(it.angle, cx, cy) canvas.translate(0f, modDistance) canvas.rotate(it.rotation, cx, cy) } } -
sprinklePaint.color = it.color canvas.drawRoundRect( cx - 7f, cy - 22f,
cx + 7f, cy + 22f, 10f, 10f, sprinklePaint) sprinklePaint.color = it.color canvas.drawRoundRect( cx - 7f, cy - 22f, cx + 7f, cy + 22f, 10f, 10f, sprinklePaint) // draw the sprinkles! // draw the sprinkles! Canvas Drawing sprinkles.forEach { sprinkles.forEach { // draw the sprinkle // draw the sprinkle // calculate the position // calculate the position // move the canvas // move the canvas val modDistance = holeRadius + padding + (ringRadius - padding * 2) * it.distance canvas.save() canvas.rotate(it.angle, cx, cy) canvas.translate(0f, modDistance) canvas.rotate(it.rotation, cx, cy) canvas.save() canvas.rotate(it.angle, cx, cy) canvas.translate(0f, modDistance) canvas.rotate(it.rotation, cx, cy) // restore the canvas // restore the canvas } } -
sprinklePaint.color = it.color canvas.drawRoundRect( cx - 7f, cy - 22f,
cx + 7f, cy + 22f, 10f, 10f, sprinklePaint) sprinklePaint.color = it.color canvas.drawRoundRect( cx - 7f, cy - 22f, cx + 7f, cy + 22f, 10f, 10f, sprinklePaint) // draw the sprinkles! // draw the sprinkles! Canvas Drawing sprinkles.forEach { sprinkles.forEach { // draw the sprinkle // draw the sprinkle // restore the canvas // restore the canvas // calculate the position // calculate the position // move the canvas // move the canvas val modDistance = holeRadius + padding + (ringRadius - padding * 2) * it.distance canvas.save() canvas.rotate(it.angle, cx, cy) canvas.translate(0f, modDistance) canvas.rotate(it.rotation, cx, cy) canvas.save() canvas.rotate(it.angle, cx, cy) canvas.translate(0f, modDistance) canvas.rotate(it.rotation, cx, cy) canvas.restore() canvas.restore() } } -
sprinklePaint.color = it.color canvas.drawRoundRect( cx - 7f, cy - 22f,
cx + 7f, cy + 22f, 10f, 10f, sprinklePaint) sprinklePaint.color = it.color canvas.drawRoundRect( cx - 7f, cy - 22f, cx + 7f, cy + 22f, 10f, 10f, sprinklePaint) // draw the sprinkles! // draw the sprinkles! Canvas Drawing sprinkles.forEach { sprinkles.forEach { // draw the sprinkle // draw the sprinkle // restore the canvas // restore the canvas // calculate the position // calculate the position // move the canvas // move the canvas val modDistance = holeRadius + padding + (ringRadius - padding * 2) * it.distance canvas.save() canvas.rotate(it.angle, cx, cy) canvas.translate(0f, modDistance) canvas.rotate(it.rotation, cx, cy) canvas.save() canvas.rotate(it.angle, cx, cy) canvas.translate(0f, modDistance) canvas.rotate(it.rotation, cx, cy) canvas.restore() canvas.restore() } } -
sprinklePaint.color = it.color canvas.drawRoundRect( cx - 7f, cy - 22f,
cx + 7f, cy + 22f, 10f, 10f, sprinklePaint) sprinklePaint.color = it.color canvas.drawRoundRect( cx - 7f, cy - 22f, cx + 7f, cy + 22f, 10f, 10f, sprinklePaint) // draw the sprinkles! // draw the sprinkles! Canvas Drawing sprinkles.forEach { sprinkles.forEach { // draw the sprinkle // draw the sprinkle // restore the canvas // restore the canvas // calculate the position // calculate the position // move the canvas // move the canvas val modDistance = holeRadius + padding + (ringRadius - padding * 2) * it.distance canvas.save() canvas.rotate(it.angle, cx, cy) canvas.translate(0f, modDistance) canvas.rotate(it.rotation, cx, cy) canvas.save() canvas.rotate(it.angle, cx, cy) canvas.translate(0f, modDistance) canvas.rotate(it.rotation, cx, cy) canvas.restore() canvas.restore() } } -
// draw the sprinkles! Canvas Drawing // draw the icing
// draw the icing // clip the hole // Clip the hole // draw the base // draw the base // draw the sprinkles! -
// draw the sprinkles! Canvas Drawing // draw the icing
// draw the icing // clip the hole // Clip the hole // draw the base // draw the base // draw the sprinkles! -
// draw the sprinkles! Canvas Drawing // draw the icing
// draw the icing // clip the hole // Clip the hole // draw the base // draw the base // draw the sprinkles! canvas.scale(0.5f, 0.5f, bounds.width() / 2f, bounds.height() / 2f) -
// draw the sprinkles! Canvas Drawing // draw the icing
// draw the icing // clip the hole // Clip the hole // draw the base // draw the base // draw the sprinkles! canvas.scale(0.5f, 0.5f, bounds.width() / 2f, bounds.height() / 2f) canvas.restore() canvas.save() -
// draw the sprinkles! Canvas Drawing // draw the icing
// draw the icing // clip the hole // Clip the hole // draw the base // draw the base // draw the sprinkles! canvas.restore() canvas.save() canvas.scale(0.5f, 0.5f, bounds.width() / 2f, bounds.height() / 2f) -
canvas.scale(scale, scale, bounds.width() / 2f, bounds.height() / 2f) canvas.scale(scale, scale,
bounds.width() / 2f, bounds.height() / 2f) // draw the sprinkles! Canvas Drawing // draw the icing // draw the icing // clip the hole // Clip the hole // draw the base // draw the base // draw the sprinkles! canvas.restore() canvas.save() -
canvas.scale(scale, scale, bounds.width() / 2f, bounds.height() / 2f) canvas.scale(scale, scale,
bounds.width() / 2f, bounds.height() / 2f) // draw the sprinkles! Canvas Drawing // draw the icing // draw the icing // clip the hole // Clip the hole // draw the base // draw the base // draw the sprinkles! canvas.restore() canvas.save() -
canvas.scale(scale, scale, bounds.width() / 2f, bounds.height() / 2f) canvas.scale(scale, scale,
bounds.width() / 2f, bounds.height() / 2f) // draw the sprinkles! Canvas Drawing // draw the icing // draw the icing // clip the hole // Clip the hole // draw the base // draw the base // draw the sprinkles! canvas.restore() canvas.save() -
// draw the sprinkles! Canvas Drawing // draw the icing
// draw the icing // clip the hole // Clip the hole // draw the base // draw the base // draw the sprinkles! canvas.restore() canvas.save() canvas.scale(scale, scale, bounds.width() / 2f, bounds.height() / 2f) canvas.scale(scale, scale, bounds.width() / 2f, bounds.height() / 2f) -
// draw the sprinkles! Canvas Drawing // draw the icing
// draw the icing // clip the hole // Clip the hole // draw the base // draw the base // draw the sprinkles!