forked from Brunost90/SoE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgressbar-TEST.py
41 lines (33 loc) · 1.31 KB
/
Progressbar-TEST.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import pyautogui
import time
#### Denne progressbaren fungerer! KAN NÅ LEGGE TIL PYAUTOGUI HVIS PROSENT STEMMER, TRYKK PÅ KNAPP "F?" LAGE RUNE ####
def get_progress_percentage(region, target_color):
screenshot = pyautogui.screenshot(region=region)
width, height = screenshot.size
if width == 0 or height == 0:
return 0.0
total_pixels = width * height
if total_pixels == 0:
return 0.0
target_pixels = 0
x_position = 0 # Initialize x_position to handle the case where no target color is found
for x in range(width):
for y in range(height):
pixel_color = screenshot.getpixel((x, y))
if pixel_color == target_color:
target_pixels += 1
x_position = x
# If no target color is found, return 0.0%
if target_pixels == 0:
return 0.0
# Calculate progress based on the horizontal position
progress_percentage = (x_position / width) * 100
return progress_percentage
# Specify the region and target color
region = (1730, 258, 180, 4)
target_color = (68, 68, 255) # Adjust the target color as needed
# Example: Track the progress every 1 second for 10 seconds
for _ in range(100):
percentage = get_progress_percentage(region, target_color)
print(f"Progress: {percentage:.2f}%")
time.sleep(0.5)