From b26442cb5e03cb708423ffe21c643c1212c33591 Mon Sep 17 00:00:00 2001 From: Victor Turansky Date: Sun, 3 May 2020 22:36:10 +0300 Subject: [PATCH 1/3] Use standard random API --- js/example-frontend-js/src/ExampleMain.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/example-frontend-js/src/ExampleMain.kt b/js/example-frontend-js/src/ExampleMain.kt index cbb6d07893..9b204a44e7 100644 --- a/js/example-frontend-js/src/ExampleMain.kt +++ b/js/example-frontend-js/src/ExampleMain.kt @@ -11,6 +11,7 @@ import org.w3c.dom.* import kotlin.browser.* import kotlin.coroutines.* import kotlin.math.* +import kotlin.random.Random fun main() { println("Starting example application...") @@ -35,8 +36,7 @@ private fun HTMLElement.setPosition(x: Double, y: Double) { } } -@Suppress("DEPRECATION") -private fun random() = kotlin.js.Math.random() +private fun random():Double = Random.nextDouble() class Application : CoroutineScope { private val body get() = document.body!! From 2292b80a2f3bec60bef35f760b480c4010f2c6fa Mon Sep 17 00:00:00 2001 From: Victor Turansky Date: Wed, 6 May 2020 12:56:23 +0300 Subject: [PATCH 2/3] Fix formatting --- js/example-frontend-js/src/ExampleMain.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/example-frontend-js/src/ExampleMain.kt b/js/example-frontend-js/src/ExampleMain.kt index 9b204a44e7..f1f212aba4 100644 --- a/js/example-frontend-js/src/ExampleMain.kt +++ b/js/example-frontend-js/src/ExampleMain.kt @@ -36,7 +36,7 @@ private fun HTMLElement.setPosition(x: Double, y: Double) { } } -private fun random():Double = Random.nextDouble() +private fun random(): Double = Random.nextDouble() class Application : CoroutineScope { private val body get() = document.body!! From bb92b50ef55299c1c47f5bc8a22bb5f58c2ef8e7 Mon Sep 17 00:00:00 2001 From: Victor Turansky Date: Wed, 6 May 2020 14:09:44 +0300 Subject: [PATCH 3/3] Inline 'random' method --- js/example-frontend-js/src/ExampleMain.kt | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/js/example-frontend-js/src/ExampleMain.kt b/js/example-frontend-js/src/ExampleMain.kt index f1f212aba4..25a73c61c0 100644 --- a/js/example-frontend-js/src/ExampleMain.kt +++ b/js/example-frontend-js/src/ExampleMain.kt @@ -36,8 +36,6 @@ private fun HTMLElement.setPosition(x: Double, y: Double) { } } -private fun random(): Double = Random.nextDouble() - class Application : CoroutineScope { private val body get() = document.body!! private val scene get() = document.getElementById("scene") as HTMLElement @@ -125,7 +123,7 @@ class Application : CoroutineScope { timer.delay(1000) // pause a bit // flip direction val t = vx - if (random() > 0.5) { + if (Random.nextDouble() > 0.5) { vx = vy vy = -t } else { @@ -150,11 +148,11 @@ class Application : CoroutineScope { animation("circle", radius) { circle -> println("Started new 'circle' coroutine #$index") val timer = AnimationTimer() - val initialAngle = random() * 2 * PI + val initialAngle = Random.nextDouble() * 2 * PI var vx = sin(initialAngle) * initialSpeed var vy = cos(initialAngle) * initialSpeed - var x = (random() * initialRange + (1 - initialRange) / 2) * sw - var y = (random() * initialRange + (1 - initialRange) / 2) * sh + var x = (Random.nextDouble() * initialRange + (1 - initialRange) / 2) * sw + var y = (Random.nextDouble() * initialRange + (1 - initialRange) / 2) * sh while (true) { val dt = timer.await() val dx = sw / 2 - x