Kanvas

Project Url: florent37/Kanvas
Introduction: Make canvas easier to use in Kotlin 😊
More: Author   ReportBugs   
Tags:

WORK IN PROGRESS

Make canvas easier to use in Kotlin 😊

✨ Use shapes & write less code to do more magic ✨

arc

//create your shapes
val background = rectShape { view ->
   color = Color.parseColor("#6fbf73")
   cornerRadius = 16.dpToPx(context)

   left = 100f
   width = view.width / 2f
   top = 100f
   height = view.height / 3f
}

//create an animator
val canvasAnimator = obtainCanvasAnimator()
fun animate(){
    canvasAnimator
            .play(background.animate().right.to(this.width.toFloat()))
            .start()
}

//draw them
override fun onDraw(canvas: Canvas) {
    super.onDraw(canvas)
    canvas.draw(background)
}

Examples

arc dots slider tree

Available shapes

Shapes link
Rect
Circle
Text
Arc
Line
Triangle
Drawable
Path

Animation

Follow the example of SwitchView

Shape animations are executed by an instance of ShapeAnimator attached to your view

val canvasAnimator = CanvasAnimator(this)

All animated methods of shapes are wrapped into the method .animate()

For example, for a CircleShape, you can animate his position (centerX) using

myCircleShape.animate().centerX.to(15);

Then use your ShapeAnimator to execute this animation

shapeAnimator.play(myCircleShape.animate().centerX.to(15);)
    .setDuration(500)
    .start()

Added support methods to Canvas

drawArc(centerX, centerY, circleRadius, startAngle, sweepAngle, paint)

drawArc(center: PointF, circleRadius, startAngle, sweepAngle, paint)

drawArc(left, top, right, bottom, startAngle, sweepAngle, useCenter, paint)

drawOval(left, top, right, bottom, startAngle, sweepAngle, useCenter, paint)

drawLine(start: PointF, end: PointF, paint)

drawRoundRect(left, top, right, bottom, rx, ry, paint)

Added support methods to Path

addRoundRect(left, top, right, bottom, rx, ry, dir: Path.Direction)

addRoundRect(left, top, right, bottom, radiiArray, dir: Path.Direction)

arcTo(centerX, centerY, circleRadius, startAngle, sweepAngle, forceMoveTo)

arcTo(center: PointF, circleRadius, startAngle, sweepAngle, forceMoveTo)

arcTo(left, top, right, bottom, startAngle, sweepAngle, forceMoveTo)

Fiches Plateau Moto : https://www.fiches-plateau-moto.fr/

Apps
About Me
GitHub: Trinea
Facebook: Dev Tools