-
Notifications
You must be signed in to change notification settings - Fork 0
/
Modifiers.py
70 lines (62 loc) · 1.88 KB
/
Modifiers.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
__author__ = 'Ian'
import MapUtility
import colorsys
def scale(arr, factor):
for x in range(len(arr)):
for y in range(len(arr[0])):
arr[x][y] *= factor
arr[x][y] = MapUtility.clamp(arr[x][y])
return arr
def invert(arr):
for x in range(len(arr)):
for y in range(len(arr[0])):
arr[x][y] = 1 - arr[x][y]
arr[x][y] = MapUtility.clamp(arr[x][y])
return arr
def cutoff(arr, val):
for x in range(len(arr)):
for y in range(len(arr[0])):
if arr[x][y] < val:
arr[x][y] = 0
return arr
def subtractConstant(arr, const):
for x in range(len(arr)):
for y in range(len(arr[0])):
arr[x][y] -= const
arr[x][y] = MapUtility.clamp(arr[x][y])
return arr
def subtract(arrA, arrB):
arrC = list()
for x in range(len(arrA)):
arrC.append(list())
for y in range(len(arrA[0])):
arrC[x].append(arrA[x][y] - arrB[x][y])
arrC[x][y] = MapUtility.clamp(arrC[x][y])
return arrC
def add(arrA, arrB):
arrC = list()
for x in range(len(arrA)):
arrC.append(list())
for y in range(len(arrA[0])):
arrC[x].append(arrA[x][y] + arrB[x][y])
arrC[x][y] = MapUtility.clamp(arrC[x][y])
return arrC
def overlay(arrA, arrB):
arrC = list()
val = 0
for x in range(len(arrA)):
arrC.append(list())
for y in range(len(arrA[0])):
if arrB[x][y] < 0.5:
val = 2.0 * arrA[x][y] * arrB[x][y]
else:
val = 1.0 - (2.0 * (1 - arrA[x][y]) * (1 - arrB[x][y]))
arrC[x].append(val)
return arrC
def evaluate(arr, cutoff):
out = list()
for x in range(len(arr)):
out.append(list())
for y in range(len(arr[0])):
out[x].append(MapUtility.evaluateColor(arr[x][y], cutoff))
return out