Didier Villevalois
01/16/2021, 9:57 AMTimo Drick
01/16/2021, 12:41 PMJohn O'Reilly
01/16/2021, 12:43 PMDidier Villevalois
01/16/2021, 12:56 PMTimo Drick
01/16/2021, 12:57 PMDidier Villevalois
01/16/2021, 12:59 PMTimo Drick
01/16/2021, 1:00 PMDidier Villevalois
01/16/2021, 1:02 PMTimo Drick
01/16/2021, 1:04 PMval bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
val canvas = Canvas(bitmap)
canvas.drawLines....
Didier Villevalois
01/16/2021, 1:09 PMandroidx.compose.ui.graphics.Canvas
doesn't seem to have a way to move pixels or be cleared...Timo Drick
01/16/2021, 1:09 PMDidier Villevalois
01/16/2021, 1:10 PMTimo Drick
01/16/2021, 1:11 PMDidier Villevalois
01/16/2021, 1:13 PMTimo Drick
01/16/2021, 1:15 PMDidier Villevalois
01/16/2021, 1:17 PMTimo Drick
01/16/2021, 1:18 PMDidier Villevalois
01/16/2021, 1:18 PMTimo Drick
01/16/2021, 1:19 PMDidier Villevalois
01/16/2021, 1:19 PMTimo Drick
01/16/2021, 1:20 PMDidier Villevalois
01/16/2021, 1:21 PMTimo Drick
01/16/2021, 1:21 PMDidier Villevalois
01/16/2021, 1:22 PMTimo Drick
01/16/2021, 1:22 PMDidier Villevalois
01/16/2021, 1:23 PMTimo Drick
01/16/2021, 1:23 PMDidier Villevalois
01/16/2021, 1:26 PMCanvas {
drawImage(thisCanvasUnderlyingBitmap, -pixelsFor16ms, 0)
// now draw the new 16ms of signal
}
John O'Reilly
01/16/2021, 1:27 PMDidier Villevalois
01/16/2021, 1:28 PMJohn O'Reilly
01/16/2021, 1:29 PMscreenData
which is generated by the emulator every 16msDidier Villevalois
01/16/2021, 1:30 PMJohn O'Reilly
01/16/2021, 1:32 PMCanvas {
drawImage(thisCanvasUnderlyingBitmap, -pixelsFor16ms, 0)
// now draw the new 16ms of signal
}
would that not also re-render every 16ms?Timo Drick
01/16/2021, 1:34 PMDidier Villevalois
01/16/2021, 1:34 PMTimo Drick
01/16/2021, 1:34 PMDidier Villevalois
01/16/2021, 1:36 PMTimo Drick
01/16/2021, 1:36 PMDidier Villevalois
01/16/2021, 1:36 PMTimo Drick
01/16/2021, 1:38 PMDidier Villevalois
01/16/2021, 1:39 PMTimo Drick
01/16/2021, 1:39 PMDidier Villevalois
01/16/2021, 1:40 PMTimo Drick
01/16/2021, 1:41 PMDidier Villevalois
01/16/2021, 1:42 PMromainguy
01/16/2021, 7:35 PMDidier Villevalois
01/16/2021, 9:37 PMromainguy
01/16/2021, 9:51 PMTimo Drick
01/17/2021, 11:34 PMconst val historySize = 500
fun fract(x: Float): Float = x - floor(x)
fun noise(c: Long): Float = fract(sin(c.toFloat()*100f) * 5647f)
class SignalMemory {
private val data = Array(historySize) { 0f }
private var pointer = 0
val ts = mutableStateOf(0L)
fun addData(value: Float) {
data[pointer] = value
pointer = (pointer+1) % data.size
ts.value += 1
}
fun size() = data.size
fun get(i: Int): Float = data[(pointer + i) % data.size]
private var running = false
fun start() {
GlobalScope.launch {
running = true
while (running) {
addData(noise(ts.value))
delay(33)
}
}
}
fun stop() {
running = false
}
}
@Composable
fun lineTest() {
val mem = remember { SignalMemory() }
onActive {
mem.start()
onDispose {
mem.stop()
}
}
Canvas(Modifier.fillMaxSize()) {
val size = drawContext.size
val stepSize = size.width / mem.size().toFloat()
val ts = mem.ts
val currentData = ts.value // just to track data changes
drawIntoCanvas {
it.scale(stepSize, -(size.height / 2f))
it.translate(0f, -1f)
for (i in 0..mem.size()) {
val x = i.toFloat()
val v = mem.get(i)
drawLine(Color.Red, Offset(x, -v), Offset(x, v), strokeWidth = 1f)
}
}
}
}
romainguy
01/17/2021, 11:40 PMTimo Drick
01/17/2021, 11:43 PMromainguy
01/17/2021, 11:46 PMTimo Drick
01/17/2021, 11:48 PMromainguy
01/17/2021, 11:48 PMTimo Drick
01/17/2021, 11:59 PMCanvas(Modifier.fillMaxSize()) {
val size = drawContext.size
val stepSize = size.width / mem.size().toFloat()
val ts = mem.ts
val currentData = ts.value // just to track data changes
val paint = Paint().apply {
strokeWidth = 1f
isAntiAlias = true
}
drawIntoCanvas {
it.scale(stepSize, -(size.height / 2f))
it.translate(0f, -1f)
val lineArray = FloatArray(mem.size() * 4)
for (i in 0 until mem.size()) {
val x = i.toFloat()
val v = mem.get(i)
val offset = i * 4
lineArray[offset] = x
lineArray[offset + 1] = -v
lineArray[offset + 2] = x
lineArray[offset + 3] = v
}
it.nativeCanvas.drawLines(lineArray, paint)
}
}
romainguy
01/18/2021, 12:01 AMTimo Drick
01/18/2021, 12:03 AMlouiscad
01/19/2021, 8:28 PMdrawLines
be part of the Compose UI Canvas API?romainguy
01/19/2021, 9:25 PMNader Jawad
01/19/2021, 9:28 PMdrawPoints
and pass in PointMode.Lines
for the corresponding PointMode
louiscad
01/19/2021, 9:38 PMdrawLines
?romainguy
01/19/2021, 9:41 PMNader Jawad
01/19/2021, 9:45 PMdrawLines
API behind the scenes and helps simplify the usage of the stepBy
parameter to be more explicit of the intent which could be used either to sets of lines between pairs of points using PointMode.Lines or draw each line connected to create a polygon using PointModes.Polygonromainguy
01/19/2021, 10:03 PMrender(Renderable, Mask, Shader, RasterState)
or something like thisRenderable
would be a set of vertices + how you interpret them (points/lines/line strips/triangles, etc.) or parametric shapes (Path, circle, etc.)louiscad
01/20/2021, 12:17 AMdrawLines
function, akin to deprecated operators in kotlinx.coroutines for people that know the RxJava APIs?Nader Jawad
01/20/2021, 12:24 AMdrawLines
method are you referring to in this case? We don't expose a drawLines method in compose. I'm not sure it makes sense to deprecate the one in the framework eitherlouiscad
01/20/2021, 12:38 AMdrawLines
function that is deprecated at error level (instead of none currently), with a ReplaceWith
clause that uses drawPoints
, and a deprecation message that explains why drawLines
from Compose UI is deprecated. I didn't meant to deprecate the one from Android, we're talking about the API of Compose UI here.
Since it'd be deprecated at error level, it wouldn't need any implementation.Nader Jawad
01/20/2021, 12:41 AMlouiscad
01/20/2021, 1:06 AMdrawLines
function on Android or other platforms that have it.