Skip to content

Commit 495b9c3

Browse files
Merge pull request #70 from sDos280/master
adding core_random_values example
2 parents 6aaf3bb + 50e74a7 commit 495b9c3

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

examples/core/core_random_values.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
"""
2+
3+
raylib [core] example - random values
4+
5+
"""
6+
from pyray import *
7+
from raylib.colors import (
8+
RAYWHITE,
9+
MAROON,
10+
LIGHTGRAY
11+
)
12+
13+
# Initialization
14+
SCREEN_WIDTH: int = 800
15+
SCREEN_HEIGHT: int = 450
16+
17+
init_window(SCREEN_WIDTH, SCREEN_HEIGHT, 'raylib [core] example - random values')
18+
19+
# set_random_seed() // Set a custom random seed if desired, by default: "time(NULL)"
20+
21+
randValue: int = get_random_value(-8, 5) # Get a random integer number between -8 and 5 (both included)
22+
23+
framesCounter: int = 0 # Variable used to count frames
24+
25+
set_target_fps(60) # Set our game to run at 60 frames-per-second
26+
27+
# Main game loop
28+
while not window_should_close(): # Detect window close button or ESC key
29+
30+
# Update
31+
# ----------------------------------------------------------------------------------
32+
framesCounter += 1
33+
34+
# Every two seconds (120 frames) a new random value is generated
35+
if ((framesCounter/120)%2) == 1:
36+
randValue = get_random_value(-8, 5)
37+
framesCounter = 0
38+
39+
# ----------------------------------------------------------------------------------
40+
41+
# Draw
42+
# ----------------------------------------------------------------------------------
43+
begin_drawing()
44+
45+
clear_background(RAYWHITE)
46+
47+
draw_text("Every 2 seconds a new random value is generated:", 130, 100, 20, MAROON)
48+
49+
draw_text(str(randValue), 360, 180, 80, LIGHTGRAY)
50+
51+
end_drawing()
52+
53+
# De-Initialization
54+
close_window() # Close window and OpenGL context

0 commit comments

Comments
 (0)