Advertisement
MAKS_Enjoyer

i got a glock in my rari (progress bar.py)

Jun 14th, 2024
540
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.30 KB | Source Code | 0 0
  1. import numpy as np
  2. import time
  3. import sys
  4.  
  5. def generate_normal_dist_values(size, min_val, max_val):
  6.     # Generates an array of 'size' normally distributed values between 'min_val' and 'max_val'.
  7.     mean = (max_val + min_val) / 2
  8.     std_dev = (max_val - min_val) / 4  # Approx. 99.7% of values within min and max
  9.     values = np.random.normal(loc=mean, scale=std_dev, size=size)
  10.     values = np.clip(values, min_val, max_val)
  11.     return values
  12.  
  13. def display_progress_bar(iteration, total, length=50):
  14.     # Displays a progress bar in the command line.
  15.     percent = "{0:.0f}".format(100 * (iteration / float(total)))
  16.     filled_length = int(length * iteration // total)
  17.     bar = '█' * filled_length + '░' * (length - filled_length)
  18.     sys.stdout.write(f'\r|{bar}| {percent}% Complete')
  19.     sys.stdout.flush()
  20.  
  21. def main():
  22.     # Main function to run the progress bar.
  23.     total_iterations = 100
  24.     min_val = 0.01
  25.     max_val = 5
  26.     sleep_multiplier = 0.15  # 150ms
  27.  
  28.     # Generate 101 normally distributed values
  29.     sleep_times = generate_normal_dist_values(total_iterations + 1, min_val, max_val)
  30.  
  31.     for i in range(total_iterations + 1):
  32.         display_progress_bar(i, total_iterations)
  33.         time.sleep(sleep_times[i] * sleep_multiplier)
  34.  
  35. if __name__ == "__main__":
  36.     main()
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement