Fixes and bouncing ball demo.

This commit is contained in:
Alexander Nozik 2021-08-15 18:45:36 +03:00
parent af327c17e3
commit 95459422d6
2 changed files with 41 additions and 23 deletions

View File

@ -9,11 +9,11 @@ import react.dom.render
import ringui.SmartTabs
import ringui.Tab
import space.kscience.dataforge.context.Context
import space.kscience.gdml.GdmlShowCase
import space.kscience.plotly.models.Trace
import space.kscience.plotly.models.appendXY
import space.kscience.plotly.scatter
import space.kscience.visionforge.Application
import space.kscience.visionforge.VisionClient
import space.kscience.visionforge.gdml.toVision
import space.kscience.visionforge.plotly.PlotlyPlugin
import space.kscience.visionforge.ring.ThreeCanvasWithControls
import space.kscience.visionforge.ring.ThreeWithControlsPlugin
@ -36,6 +36,8 @@ private class JsPlaygroundApp : Application {
val element = document.getElementById("playground") ?: error("Element with id 'playground' not found on page")
val bouncingSphereTrace = Trace()
val bouncingSphere = SolidGroup {
sphere(5.0, "ball") {
detail = 16
@ -52,7 +54,9 @@ private class JsPlaygroundApp : Application {
time += dt
velocity -= g * dt
y = y.toDouble() + velocity * dt
bouncingSphereTrace.appendXY(time, y)
if (y.toDouble() <= 2.5) {
//conservation of energy
velocity = sqrt(2 * g * h)
}
}
@ -63,9 +67,6 @@ private class JsPlaygroundApp : Application {
y = -2.5
}
}
val visionOfD0 = GdmlShowCase.babyIaxo().toVision()
val random = Random(112233)
val visionOfSpheres = SolidGroup {
@ -92,6 +93,10 @@ private class JsPlaygroundApp : Application {
}
SmartTabs("gravity") {
Tab("gravity") {
styledDiv {
css{
height = 50.vh
}
child(ThreeCanvasWithControls) {
attrs {
context = playgroundContext
@ -99,15 +104,30 @@ private class JsPlaygroundApp : Application {
}
}
}
styledDiv {
css{
height = 40.vh
}
Tab("D0") {
child(ThreeCanvasWithControls) {
Plotly {
attrs {
context = playgroundContext
solid = visionOfD0
plot = space.kscience.plotly.Plotly.plot {
traces(bouncingSphereTrace)
}
}
}
}
}
// Tab("D0") {
// child(ThreeCanvasWithControls) {
// attrs {
// context = playgroundContext
// solid = GdmlShowCase.babyIaxo().toVision()
// }
// }
// }
Tab("spheres") {
child(ThreeCanvasWithControls) {
attrs {

View File

@ -1,4 +1,4 @@
import kotlinx.css.*
import kotlinx.css.flex
import org.w3c.dom.Element
import org.w3c.dom.HTMLElement
import react.RProps
@ -27,8 +27,6 @@ val Plotly = functionalComponent<PlotlyProps>("Plotly"){props ->
styledDiv {
css {
maxWidth = 100.vw
maxHeight = 100.vh
flex(1.0)
}
ref = elementRef