1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

rand: simplify rand.PRNG, move to optional types for error handling (#13570)

This commit is contained in:
Subhomoy Haldar
2022-02-23 16:06:14 +05:30
committed by GitHub
parent 5c0b7b0d05
commit 114a341f5f
49 changed files with 609 additions and 1586 deletions

View File

@@ -60,22 +60,22 @@ fn main() {
user_data: app
)
for i in 0 .. max_stars {
app.stars[i].x = rand.f32_in_range(-200.0, 200.0)
app.stars[i].y = rand.f32_in_range(-200.0, 200.0)
app.stars[i].z = rand.f32_in_range(-200.0, -100.0)
app.stars[i].r = rand.f32_in_range(0.1, 1.0)
app.stars[i].g = rand.f32_in_range(0.1, 1.0)
app.stars[i].b = rand.f32_in_range(0.1, 1.0)
app.stars[i].x = rand.f32_in_range(-200.0, 200.0) or { -200.0 }
app.stars[i].y = rand.f32_in_range(-200.0, 200.0) or { -200.0 }
app.stars[i].z = rand.f32_in_range(-200.0, -100.0) or { -200.0 }
app.stars[i].r = rand.f32_in_range(0.1, 1.0) or { 0.1 }
app.stars[i].g = rand.f32_in_range(0.1, 1.0) or { 0.1 }
app.stars[i].b = rand.f32_in_range(0.1, 1.0) or { 0.1 }
}
for i in 0 .. max_v_letters {
app.v_letters[i].x = rand.f32_in_range(-20.0, 20.0)
app.v_letters[i].y = rand.f32_in_range(-20.0, 20.0)
app.v_letters[i].z = rand.f32_in_range(-5.0, -1.0)
app.v_letters[i].w = rand.f32_in_range(5, 20)
app.v_letters[i].x = rand.f32_in_range(-20.0, 20.0) or { -20.0 }
app.v_letters[i].y = rand.f32_in_range(-20.0, 20.0) or { -20.0 }
app.v_letters[i].z = rand.f32_in_range(-5.0, -1.0) or { -5.0 }
app.v_letters[i].w = rand.f32_in_range(5, 20) or { 5 }
app.v_letters[i].h = app.v_letters[i].w
app.v_letters[i].angle = rand.f32_in_range(0, 6.283184)
app.v_letters[i].dangle = rand.f32_in_range(-0.05, 0.05)
app.v_letters[i].dz = rand.f32_in_range(-0.1, -0.01)
app.v_letters[i].angle = rand.f32_in_range(0, 6.283184) or { 0 }
app.v_letters[i].dangle = rand.f32_in_range(-0.05, 0.05) or { -0.05 }
app.v_letters[i].dz = rand.f32_in_range(-0.1, -0.01) or { -0.1 }
}
app.gg.run()
}
@@ -102,9 +102,9 @@ fn (mut app App) draw() {
sgl.v3f_c3f(s.x, s.y, s.z, s.r, s.g, s.b)
app.stars[i].z += 0.3
if app.stars[i].z > -1.0 {
app.stars[i].x = rand.f32_in_range(-200.0, 200.0)
app.stars[i].y = rand.f32_in_range(-200.0, 200.0)
app.stars[i].z = rand.f32_in_range(-200.0, -100.0)
app.stars[i].x = rand.f32_in_range(-200.0, 200.0) or { -200.0 }
app.stars[i].y = rand.f32_in_range(-200.0, 200.0) or { -200.0 }
app.stars[i].z = rand.f32_in_range(-200.0, -100.0) or { -200.0 }
}
}
sgl.end()
@@ -119,15 +119,15 @@ fn (mut app App) draw() {
app.v_letters[i].z += app.v_letters[i].dz
app.v_letters[i].angle += app.v_letters[i].dangle
if app.v_letters[i].z > -60.0 {
app.v_letters[i].x += rand.f32_in_range(-0.05, 0.05)
app.v_letters[i].y += rand.f32_in_range(-0.05, 0.05)
app.v_letters[i].x += rand.f32_in_range(-0.05, 0.05) or { -0.05 }
app.v_letters[i].y += rand.f32_in_range(-0.05, 0.05) or { -0.05 }
}
if app.v_letters[i].z < -95.0 {
app.v_letters[i].h *= 0.8
app.v_letters[i].w *= 0.8
}
if app.v_letters[i].z < -100.0 {
app.v_letters[i].z = rand.f32_in_range(-5.0, -1.0)
app.v_letters[i].z = rand.f32_in_range(-5.0, -1.0) or { -5.0 }
app.v_letters[i].h = 10.0
app.v_letters[i].w = 10.0
}