Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use standard random API #1988

Merged
merged 3 commits into from
May 6, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions js/example-frontend-js/src/ExampleMain.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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...")
Expand All @@ -35,9 +36,6 @@ private fun HTMLElement.setPosition(x: Double, y: Double) {
}
}

@Suppress("DEPRECATION")
private fun random() = kotlin.js.Math.random()

class Application : CoroutineScope {
private val body get() = document.body!!
private val scene get() = document.getElementById("scene") as HTMLElement
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down