forked from chezsick/MyGist
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ff2clear.py
executable file
·143 lines (143 loc) · 4.52 KB
/
ff2clear.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import sys
import math
mode = sys.argv[1]
if not "farbfeld" == sys.stdin.read(8):
exit(1)
size = sys.stdin.read(8)
x = (pow(256,3)*ord(size[0]))+(pow(256,2)*ord(size[1]))+(pow(256,1)*ord(size[2]))+(pow(256,0)*ord(size[3]))
y = (pow(256,3)*ord(size[4]))+(pow(256,2)*ord(size[5]))+(pow(256,1)*ord(size[6]))+(pow(256,0)*ord(size[7]))
n = x*y
sys.stdout.write("farbfeld")
sys.stdout.write(size)
rr=0
gg=0
bb=0
if mode == "cc":
ahe = sys.argv[2]
bhe = sys.argv[3]
ra = int(ahe[0:2],16)
ga = int(ahe[2:4],16)
ba = int(ahe[4:6],16)
rb = int(bhe[0:2],16)
gb = int(bhe[2:4],16)
bc = int(bhe[4:6],16)
while bool(n):
o = sys.stdin.read(8)
r = (ord(o[0])*256)+ord(o[1])
g = (ord(o[2])*256)+ord(o[3])
b = (ord(o[4])*256)+ord(o[5])
if not bool(n%x):
rr=r
gg=g
bb=b
dr=r-rr
dg=g-gg
db=b-bb
rv=r
gv=g
bv=b
d=(dr+dg+db)/3
if mode == "rc":
if d < 0:
rv = min(r + abs(d),65535)
elif d > 0:
rv = max(r - abs(d),0)
if mode == "gm":
if d < 0:
gv = min(g + abs(d),65535)
elif d > 0:
gv = max(g - abs(d),0)
if mode == "by":
if d < 0:
bv = min(b + abs(d),65535)
elif d > 0:
bv = max(b - abs(d),0)
if mode == "cr":
if d < 0:
gv = min(g + abs(d),65535)
bv = min(b + abs(d),65535)
elif d > 0:
gv = max(g - abs(d),0)
bv = max(b - abs(d),0)
if mode == "mg":
if d < 0:
rv = min(r + abs(d),65535)
bv = min(b + abs(d),65535)
elif d > 0:
rv = max(r - abs(d),0)
bv = max(b - abs(d),0)
if mode == "yb":
if d < 0:
rv = min(r + abs(d),65535)
gv = min(g + abs(d),65535)
elif d > 0:
rv = max(r - abs(d),0)
gv = max(g - abs(d),0)
if mode == "rb":
if d < 0:
rv = min(r + abs(d),65535)
gv = g
bv = max(b - abs(d),0)
elif d > 0:
rv = max(r - abs(d),0)
gv = g
bv = min(b + abs(d),65535)
if mode == "br":
if d < 0:
rv = max(r - abs(d),0)
gv = g
bv = min(b + abs(d),65535)
elif d > 0:
rv = min(r + abs(d),65535)
gv = g
bv = max(b - abs(d),0)
if mode == "cc":
if d < 0:
rv = min(r + (int((ra/255.0)*abs(d))),65535)
gv = min(g + (int((ga/255.0)*abs(d))),65535)
bv = min(b + (int((ba/255.0)*abs(d))),65535)
elif d > 0:
rv = max(r - (int((1-(rb/255.0))*(abs(d)))),0)
gv = max(g - (int((1-(gb/255.0))*(abs(d)))),0)
bv = max(b - (int((1-(bc/255.0))*(abs(d)))),0)
if mode == "rgb":
if d < 0:
rv = min(r + int(65535*(math.sin(abs(d)/65535.0)*(math.pi*0.5))),65535)
gv = min(g + int(65535*(math.sin(abs(d)/65535.0)*(math.pi*0.25))),65535)
bv = min(b + int(65535*(math.sin(abs(d)/65535.0)*(math.pi*0.125))),65535)
elif d > 0:
rv = max(r - int(65535*(math.sin(abs(d)/65535.0)*(math.pi*0.5))),0)
gv = max(g - int(65535*(math.sin(abs(d)/65535.0)*(math.pi*0.25))),0)
bv = max(b - int(65535*(math.sin(abs(d)/65535.0)*(math.pi*0.125))),0)
if mode == "bgr":
if d < 0:
rv = min(r + int(65535*(math.sin(abs(d)/65535.0)*(math.pi*0.125))),65535)
gv = min(g + int(65535*(math.sin(abs(d)/65535.0)*(math.pi*0.25))),65535)
bv = min(b + int(65535*(math.sin(abs(d)/65535.0)*(math.pi*0.5))),65535)
elif d > 0:
rv = max(r - int(65535*(math.sin(abs(d)/65535.0)*(math.pi*0.125))),0)
gv = max(g - int(65535*(math.sin(abs(d)/65535.0)*(math.pi*0.25))),0)
bv = max(b - int(65535*(math.sin(abs(d)/65535.0)*(math.pi*0.5))),0)
if mode == "rgb+":
if d < 0:
rv = min(r + (int(65535*(math.sin(abs(d)/65535.0)*(math.pi*0.5))-(d/1))),65535)
gv = min(g + (int(65535*(math.sin(abs(d)/65535.0)*(math.pi*0.25))-(d/2))),65535)
bv = min(b + (int(65535*(math.sin(abs(d)/65535.0)*(math.pi*0.125))-(d/3))),65535)
elif d > 0:
rv = max(r - (int(65535*(math.sin(abs(d)/65535.0)*(math.pi*0.5))+(d/1))),0)
gv = max(g - (int(65535*(math.sin(abs(d)/65535.0)*(math.pi*0.25))+(d/2))),0)
bv = max(b - (int(65535*(math.sin(abs(d)/65535.0)*(math.pi*0.125))+(d/3))),0)
if mode == "bgr+":
if d < 0:
rv = min(r + (int(65535*(math.sin(abs(d)/65535.0)*(math.pi*0.125))-(d/3))),65535)
gv = min(g + (int(65535*(math.sin(abs(d)/65535.0)*(math.pi*0.25))-(d/2))),65535)
bv = min(b + (int(65535*(math.sin(abs(d)/65535.0)*(math.pi*0.5))-(d/1))),65535)
elif d > 0:
rv = max(r - (int(65535*(math.sin(abs(d)/65535.0)*(math.pi*0.125))+(d/3))),0)
gv = max(g - (int(65535*(math.sin(abs(d)/65535.0)*(math.pi*0.25))+(d/2))),0)
bv = max(b - (int(65535*(math.sin(abs(d)/65535.0)*(math.pi*0.5))+(d/1))),0)
sys.stdout.write("%s%s%s%s%s%s%s%s" %(chr(rv/256),chr(rv%256),chr(gv/256),chr(gv%256),chr(bv/256),chr(bv%256),o[6],o[7]))
rr=r
gg=g
bb=b
n=n-1