Skip to content

Commit 70bb565

Browse files
authored
Merge branch 'main' into some-enhancements
2 parents 1286cc1 + 860a96a commit 70bb565

File tree

229 files changed

+369939
-210
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

229 files changed

+369939
-210
lines changed

.DS_Store

0 Bytes
Binary file not shown.

Address Validator/AddressValidator.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
def addressVal(address):
2+
dot = address.find(".")
3+
at = address.find("@")
4+
if (dot == -1):
5+
print("Invalid")
6+
elif (at == -1):
7+
print("Invalid")
8+
else:
9+
print("Valid")
10+
11+
print("This program will decide if your input is a valid email address")
12+
while(True):
13+
print("A valid email address needs an '@' symbol and a '.'")
14+
x = input("Input your email address:")
15+
16+
addressVal(x)

Address Validator/README.md

+21

Animalese_translator/README.md

+45

Animalese_translator/main.py

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
import os
2+
#it lets the user interact with the native OS Python is currently running on.
3+
4+
from pprint import pprint
5+
#pprint enables printing in situations where errors wouldn't let them print... or something like that
6+
7+
from playsound import playsound
8+
#playsound needs 1 argument in order to work: the sound file path.
9+
10+
from scipy.io import wavfile
11+
#scipy.io (Input/Output)
12+
13+
from scipy.io.wavfile import write
14+
#import the function of writing a soundfile from a 1D or 2D Numpy array of either integer or float data-type.
15+
16+
import numpy as np
17+
# if you pip install scipy numpy will come too
18+
19+
voice_path = "/home/wilson/Documentos/git_repo/python-mini-project/Animalese_translator/voices/guy3"
20+
files = os.listdir(voice_path)
21+
# lists the containing names of the entries of the specified directory
22+
23+
files.sort()
24+
# lists voices from A to Z
25+
26+
sounds = {}
27+
for file in files:
28+
print(file)
29+
raw_name = file.split(".")[0]
30+
# will return 'a' from 'a.wav'
31+
32+
fp = os.path.join(voice_path, file)
33+
# will do 'pathname/a' to find the file
34+
35+
rate, data = wavfile.read(fp)
36+
# x = 48000
37+
# [[-38 24]
38+
# [-21 20]
39+
# [-30 23]
40+
# ...
41+
# [ 40 71]
42+
# [ 26 108]
43+
# [ 57 226]]
44+
45+
channel_one = data[:, 0]
46+
#[-38 -21 -30 ... 40 26 57]
47+
48+
sounds[raw_name] = channel_one
49+
# pprint(sounds)
50+
51+
sample_rate = 48000
52+
speed_multiplier = 2.2
53+
advance = 0.15 * sample_rate
54+
space_skip = 0.4 * advance
55+
56+
# say_this = "This is a test of the animal crossing style talking machine"
57+
# say_this = "mestr lokee i mess yu bro"
58+
# say_this = "ha"
59+
# say_this = "pastee luuk at des"
60+
# say_this = "kil haw es yor de goeng"
61+
# say_this = "weleam haw was yor de"
62+
say_this = "i med somteng kul"
63+
# say_this = "ame i lov yuu vere alat"
64+
# say_this = "ef yu wurk hard yu wel hav a gud lif"
65+
66+
say = say_this.lower().strip()
67+
#lowercased, removes leading/trailing whitespaces.
68+
69+
cursor = 0
70+
notes = []
71+
for char in say:
72+
notes.append((char, cursor))
73+
if char == " ":
74+
cursor += space_skip
75+
else:
76+
cursor += advance
77+
# advance the cursor by the length of the last note
78+
last_char = say[-1]
79+
last_note = sounds[last_char]
80+
last_note_length = last_note.shape[0]
81+
cursor += last_note_length
82+
83+
end_pad = sample_rate * 1.0
84+
buffer_length = int(cursor + end_pad)
85+
base = np.zeros(buffer_length, dtype=np.int16)
86+
87+
for note in notes:
88+
char = note[0]
89+
cursor = note[1]
90+
if char not in sounds:
91+
continue
92+
sound = sounds[char]
93+
start = int(cursor)
94+
end = int(start + sound.shape[0])
95+
print(f"Adding {char} from {start} to {end}")
96+
selection = base[start:end]
97+
print(selection.shape)
98+
print(sound.shape)
99+
base[start:end] += sound
100+
101+
output_dir = "output"
102+
if not os.path.exists(output_dir):
103+
os.makedirs(output_dir)
104+
105+
name = say_this.replace(" ", "_")
106+
file_path = os.path.join(output_dir, name + '.wav')
107+
write_rate = int(sample_rate*speed_multiplier)
108+
write(file_path, write_rate, base.astype(np.int16))
109+
playsound(file_path)
110+
# for file in files:
111+
# playsound(voice_path + "/" + file)
79.6 KB
Binary file not shown.
79.6 KB
Binary file not shown.
70.8 KB
Binary file not shown.
60.8 KB
Binary file not shown.
72.6 KB
Binary file not shown.
83.9 KB
Binary file not shown.
46.5 KB
Binary file not shown.
73.3 KB
Binary file not shown.
78.1 KB
Binary file not shown.
46 KB
Binary file not shown.
45.3 KB
Binary file not shown.
70.1 KB
Binary file not shown.
56.5 KB
Binary file not shown.
66.1 KB
Binary file not shown.
70.8 KB
Binary file not shown.
50.3 KB
Binary file not shown.
66.6 KB
Binary file not shown.
95.2 KB
Binary file not shown.
66.6 KB
Binary file not shown.
60.8 KB
Binary file not shown.
75.8 KB
Binary file not shown.
80.9 KB
Binary file not shown.
76.3 KB
Binary file not shown.
72.3 KB
Binary file not shown.
75.8 KB
Binary file not shown.
83.9 KB
Binary file not shown.

Binary_Search_Tree/README.md

+23

Binary_Search_Tree/bst.py

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
class BST:
2+
3+
def __init__(self,val,left,right):
4+
self.val = val
5+
self.left = left
6+
self.right = right
7+
8+
def addHelper(self,root,data):
9+
10+
# case for reaching current leafs, base cases
11+
if root.val < data and root.right == None:
12+
root.right = BST(data,None,None)
13+
return "insertion completed"
14+
elif root.val > data and root.left == None:
15+
root.left = BST(data,None,None)
16+
return "insertion completed"
17+
18+
# else we continue tracing downwards
19+
if root.val < data:
20+
return self.add(root.right,data)
21+
elif root.val > data:
22+
return self.add(root.left,data)
23+
else:
24+
return "insertion failed: duplicate value"
25+
26+
def add(self,root,data):
27+
if root == None:
28+
return "insertion failed: empty root"
29+
return self.addHelper(root,data)
30+
31+
def restructdata(self,root):
32+
# base case: we reach a leaf
33+
if root == None or (root.left == None and root.right == None):
34+
root = None
35+
return "restructure finished"
36+
37+
# need dummy nodes to compare target value to children value
38+
v1 = float('-inf')
39+
v2 = float('inf')
40+
if root.left != None:
41+
v1 = root.left.val
42+
if root.right != None:
43+
v2 = root.right.val
44+
45+
temp = root.val
46+
if v1 > v2 or v2 == float('inf'):
47+
root.val = root.left.val
48+
root.left.val = temp
49+
return self.restructdata(root.left)
50+
else:
51+
root.val = root.right.val
52+
root.right.val = temp
53+
return self.restructdata(root.right)
54+
55+
56+
def removeHelper(self,root,data):
57+
if root == None:
58+
return "deletion failed: could not find value"
59+
60+
# adhering to typical bst properties
61+
if root.val < data:
62+
return self.removeHelper(root.right,data)
63+
elif root.val > data:
64+
return self.removeHelper(root.left,data)
65+
else:
66+
temp = root.val
67+
v1 = float('-inf')
68+
v2 = float('inf')
69+
if root.left != None:
70+
v1 = root.left.val
71+
elif root.right != None:
72+
v2 = root.right.val
73+
74+
if v1 > v2 or v2 == float('inf'):
75+
root.val = root.left.val
76+
root.left.val = temp
77+
return self.restructdata(root.left)
78+
else:
79+
root.val = root.right.val
80+
root.right.val = temp
81+
return self.restructdata(root.right)
82+
83+
def remove(self,root,data):
84+
if root == None:
85+
return "deletion failed: deleting from an empty tree"
86+
return self.removeHelper(root,data)
87+
88+
89+
90+
534 Bytes
Binary file not shown.
2.84 KB
Binary file not shown.

Caterpillar_Game/Caterpillar.py

+30-7
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,25 @@
2828
score_turtle.hideturtle()
2929
score_turtle.speed(0)
3030

31+
obstacle = t.Turtle()
32+
obstacle.shape('circle') # You can choose any shape
33+
obstacle.color('red') # Choose a distinct color for obstacles
34+
obstacle.penup()
35+
obstacle.hideturtle()
36+
37+
num_obstacles = 5 # Number of obstacles
38+
obstacles = []
39+
40+
for _ in range(num_obstacles):
41+
new_obstacle = t.Turtle()
42+
new_obstacle.shape('circle')
43+
new_obstacle.color('red')
44+
new_obstacle.penup()
45+
new_obstacle.setposition(rd.randint(-200, 200), rd.randint(-200, 200))
46+
new_obstacle.showturtle()
47+
obstacles.append(new_obstacle)
48+
49+
3150
def outside_window():
3251
left_wall = -t.window_width()/2
3352
right_Wall = t.window_width()/2
@@ -77,16 +96,20 @@ def start_game():
7796

7897
while True:
7998
caterpillar.forward(caterpillar_speed)
80-
if caterpillar.distance(leaf) < 20:
81-
place_leaf()
82-
caterpillar_length = caterpillar_length + 1
83-
caterpillar.shapesize(1,caterpillar_length,1)
84-
caterpillar_speed = caterpillar_speed + 1
85-
score = score + 10
86-
display_score(score)
99+
for obstacle in obstacles:
100+
if caterpillar.distance(leaf) < 20:
101+
place_leaf()
102+
caterpillar_length = caterpillar_length + 1
103+
caterpillar.shapesize(1,caterpillar_length,1)
104+
caterpillar_speed = caterpillar_speed + 1
105+
score = score + 10
106+
display_score(score)
107+
game_over()
108+
break
87109
if outside_window():
88110
game_over()
89111
break
112+
90113

91114
def move_up():
92115
caterpillar.setheading(90)

Chess_Game/ChessGame.py

+6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
MAX_FPS = 15
88
IMAGES = {}
99

10+
11+
icon = p.image.load("images\icon.ico")
12+
p.display.set_icon(icon)
13+
14+
p.display.set_caption("Chess Game")
15+
1016
def loadImages():
1117
pieces = ['wp', 'wR', 'wN', 'wB', 'wQ', 'wK', 'bp', 'bR', 'bN', 'bB', 'bQ', 'bK' ]
1218
for piece in pieces:
Binary file not shown.

Chess_Game/images/icon.ico

264 KB
Binary file not shown.

Color_Game/README.md

+1-1

Color_Game/highest_score.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
5

Color_Game/main.py

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ def start_game(event):
7474
window = tk.Tk()
7575
font = 'Helvetica'
7676
window.title("Color Game")
77+
window.iconbitmap("color_game_icon.ico")
7778
window.geometry("375x250")
7879
window.resizable(False, False)
7980

0 commit comments

Comments
 (0)