coracle was originally an experiment creating cross-platform sketches/drawings using Kotlin with a pattern and syntax similar to processing (You can view a few dozen of those sketches in the digital garden).
This iteration of coracle solely targets Compose and gives me a very simple method for creating complex visuals in Android apps. Functionality is ported from the original implementation as and when I need it but the main api is in place and works very smoothly with excellent interop with Compose canvas.
Because Coracle augments Compose so well you can develop drawings/sketches from within Android Studio using Compose Previews with full animation support - you don't need to debug on your phone at all.
There's no Maven dependency or .aar, just copy the coracle
package to your own project:
An example drawing showing the basic pattern and interop with Compose:
package orllewin.coraclecompose.drawings
import androidx.compose.foundation.layout.size
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.drawscope.DrawScope
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.drawText
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import orllewin.coracle.CoracleCanvas
import orllewin.coracle.Drawing
class HelloCoracle: Drawing() {
override fun setup(width: Int, height: Int) {
super.setup(width, height)
stroke(Color.White)
}
override fun draw(scope: DrawScope) {
super.draw(scope)
background(Color.Black)
var y = 0
var d = 3
while(y < height){
var x = 0
while(x < width){
line(x, y, x, y + d)
x += d
}
y += d
d++
}
//Easily mix Coracle and Compose drawing:
scope.apply {
drawText(
textMeasurer = textMeasurer,
text = "Hello, Coracle",
style = TextStyle(
fontSize = 95.sp,
fontWeight = FontWeight.Medium,
color = Color.White,
background = Color.Black.copy(alpha = 0.5f)
),
topLeft = Offset(16.dp.toPx(), 16.dp.toPx())
)
}
noLoop()
}
}
@Preview
@Composable
fun HelloCoraclePreview(){
CoracleCanvas(
modifier = Modifier.size(480.dp, 640.dp),
drawing = HelloCoracle()
)
}