@@ -11,6 +11,7 @@ import org.w3c.dom.*
11
11
import kotlin.browser.*
12
12
import kotlin.coroutines.*
13
13
import kotlin.math.*
14
+ import kotlin.random.Random
14
15
15
16
fun main () {
16
17
println (" Starting example application..." )
@@ -35,9 +36,6 @@ private fun HTMLElement.setPosition(x: Double, y: Double) {
35
36
}
36
37
}
37
38
38
- @Suppress(" DEPRECATION" )
39
- private fun random () = kotlin.js.Math .random()
40
-
41
39
class Application : CoroutineScope {
42
40
private val body get() = document.body!!
43
41
private val scene get() = document.getElementById(" scene" ) as HTMLElement
@@ -125,7 +123,7 @@ class Application : CoroutineScope {
125
123
timer.delay(1000 ) // pause a bit
126
124
// flip direction
127
125
val t = vx
128
- if (random () > 0.5 ) {
126
+ if (Random .nextDouble () > 0.5 ) {
129
127
vx = vy
130
128
vy = - t
131
129
} else {
@@ -150,11 +148,11 @@ class Application : CoroutineScope {
150
148
animation(" circle" , radius) { circle ->
151
149
println (" Started new 'circle' coroutine #$index " )
152
150
val timer = AnimationTimer ()
153
- val initialAngle = random () * 2 * PI
151
+ val initialAngle = Random .nextDouble () * 2 * PI
154
152
var vx = sin(initialAngle) * initialSpeed
155
153
var vy = cos(initialAngle) * initialSpeed
156
- var x = (random () * initialRange + (1 - initialRange) / 2 ) * sw
157
- var y = (random () * initialRange + (1 - initialRange) / 2 ) * sh
154
+ var x = (Random .nextDouble () * initialRange + (1 - initialRange) / 2 ) * sw
155
+ var y = (Random .nextDouble () * initialRange + (1 - initialRange) / 2 ) * sh
158
156
while (true ) {
159
157
val dt = timer.await()
160
158
val dx = sw / 2 - x
0 commit comments