-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtil.py
More file actions
64 lines (42 loc) · 1.59 KB
/
Copy pathUtil.py
File metadata and controls
64 lines (42 loc) · 1.59 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python
"""Mostly crappy miscellaneous functions"""
__author__ = "John Sheehan"
__email__ = "jennasys@yahoo.com"
__version__ = "1.0.0"
__date__ = "Mar-06-2013"
import pygame
def getFraction(value, denominator):
whole_num, remainder = divmod(value, 1)
numerator = round(remainder * denominator)
while numerator % 2 == 0 and numerator != 0:
numerator = numerator / 2
denominator = denominator / 2
if numerator == 0:
return f"{whole_num:0.0f}"
elif whole_num != 0:
return f"{whole_num:0.0f}-{numerator:0.0f}/{denominator:0.0f}"
else:
return f"{numerator:0.0f}/{denominator:0.0f}"
def inputbox(screen, label, value, pos, size, bg_color, fg_color):
# font = pygame.font.SysFont(pygame.font.get_default_font(), int(screen.get_size()[0] * 0.025))
font = pygame.font.SysFont("Arial", int(screen.get_size()[0] * 0.02))
lbl = font.render(label, True, fg_color)
lbl_rect = lbl.get_rect()
rect = pygame.Rect([0, 0, size - lbl_rect.width, int(screen.get_size()[0] * 0.025)])
offset = (3, 1)
rect.left = pos[0] + lbl_rect.width
rect.top = pos[1]
pygame.draw.rect(screen, bg_color, rect, 0)
pygame.draw.rect(screen, (128,128,128), rect, 1)
rect.left += offset[0]
rect.top += offset[1]
if len(label) != 0:
screen.blit(lbl, pos)
if len(value) != 0:
screen.blit(font.render(value, True, fg_color), rect.topleft)
if __name__=="__main__":
num = 1.0
while num != 0:
num = input("Enter number:")
if num != 0:
print(getFraction(float(num), 64))