From 50e74a7e2605e8e10a9ea76ec1e57adfdc8cbca6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D7=93=D7=95=D7=A8=20=D7=A9=D7=A4=D7=99=D7=A8=D7=90?= Date: Thu, 28 Jul 2022 12:56:11 +0300 Subject: [PATCH] adding core_random_values example --- examples/core/core_random_values.py | 54 +++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 examples/core/core_random_values.py diff --git a/examples/core/core_random_values.py b/examples/core/core_random_values.py new file mode 100644 index 0000000..5e1d0f6 --- /dev/null +++ b/examples/core/core_random_values.py @@ -0,0 +1,54 @@ +""" + +raylib [core] example - random values + +""" +from pyray import * +from raylib.colors import ( + RAYWHITE, + MAROON, + LIGHTGRAY +) + +# Initialization +SCREEN_WIDTH: int = 800 +SCREEN_HEIGHT: int = 450 + +init_window(SCREEN_WIDTH, SCREEN_HEIGHT, 'raylib [core] example - random values') + +# set_random_seed() // Set a custom random seed if desired, by default: "time(NULL)" + +randValue: int = get_random_value(-8, 5) # Get a random integer number between -8 and 5 (both included) + +framesCounter: int = 0 # Variable used to count frames + +set_target_fps(60) # Set our game to run at 60 frames-per-second + +# Main game loop +while not window_should_close(): # Detect window close button or ESC key + + # Update + # ---------------------------------------------------------------------------------- + framesCounter += 1 + + # Every two seconds (120 frames) a new random value is generated + if ((framesCounter/120)%2) == 1: + randValue = get_random_value(-8, 5) + framesCounter = 0 + + # ---------------------------------------------------------------------------------- + + # Draw + # ---------------------------------------------------------------------------------- + begin_drawing() + + clear_background(RAYWHITE) + + draw_text("Every 2 seconds a new random value is generated:", 130, 100, 20, MAROON) + + draw_text(str(randValue), 360, 180, 80, LIGHTGRAY) + + end_drawing() + +# De-Initialization +close_window() # Close window and OpenGL context