-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
48 lines (37 loc) · 1.12 KB
/
utils.py
File metadata and controls
48 lines (37 loc) · 1.12 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
import random
def arrayToMatrix(Array, height, width,colour):
if not colour:
Matrix = []
for h in range(height):
Row = []
for w in range(width):
Row.append(Array[h * width + w])
Matrix.append(Row)
return Matrix
else:
return Array
def matrixToArray(Matrix, height, width):
Array = []
for h in range(height):
for w in range(width):
Array.append(Matrix[h][w])
return Array
def clone(Matrix):
return [row[:] for row in Matrix]
def noise(Matrix, width, height, val):
new_Matrix = clone(Matrix)
for h in range(height):
for w in range(width):
x = random.randint(0, 20)
if (x == 0):
new_Matrix[h][w] = 0
if (x == 20):
new_Matrix[h][w] = val
return new_Matrix
def ascii(image, width, height):
new_image = clone(image)
chars = ["B", "S", "#", "&", "@", "$", "%", "*", "!", ":", "."]
for h in range(height):
for w in range(width):
new_image[h][w] = chars[new_image[h][w] // 25]
return new_image