- Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathColorGradient.rb
More file actions
Latest commit
executable file
·23 lines (23 loc) · 682 Bytes
/
Copy pathColorGradient.rb
File metadata and controls
executable file
·23 lines (23 loc) · 682 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
classColorGradient
# initialize with three arrays of r,g,b values
definitialize(c1,c2,c3)
@c1=c1
@c2=c2
@c3=c3
end
# ratio is fraction between 0 and 1
defgetColor(ratio)
if(ratio < 0.5)
ratio *= 2
red=(@c1[0] * (1 - ratio) + @c2[0] * ratio).round
green=(@c1[1] * (1 - ratio) + @c2[1] * ratio).round
blue=(@c1[2] * (1 - ratio) + @c2[2] * ratio).round
else
ratio=(ratio - 0.5)*2
red=(@c2[0] * (1 - ratio) + @c3[0] * ratio).round
green=(@c2[1] * (1 - ratio) + @c3[1] * ratio).round
blue=(@c2[2] * (1 - ratio) + @c3[2] * ratio).round
end
return[red,green,blue]
end
end