Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fromHSV( Hue ∈ [0,360], Saturation ∈ [0,100], Value ∈ [0,100] )
- function fromHSV(H,S,V)
- H = math.abs(H)
- local C = V * S
- local X = C * math.abs((H/60)%2-1)
- local m = V - C
- local HSV
- if H > 300 and H < 360 then
- HSV = {C,0,X}
- elseif H > 240 and H < 300 then
- HSV = {X,0,C}
- elseif H > 180 and H < 240 then
- HSV = {0,X,C}
- elseif H > 120 and H < 180 then
- HSV = {0,C,X}
- elseif H > 60 and H < 120 then
- HSV = {X,C,0}
- elseif H < 60 then
- HSV = {C ,X, 0}
- end
- local RGB = {(HSV[1]+m)*2.55,(HSV[2]+m)*2.55,(HSV[3]+m)*2.55}
- end
- --// method: convert Color3PlusData to Color3 userdata
- function Color3PlusData:toColor3()
- return Color3.new(self.r,self.g,self.b);
- end
- --// method: convert Color3PlusData to int
- function Color3PlusData:toInt()
- return floor(self.r*255)*256^2+floor(self.g*255)*256+floor(self.b*255)
- end
- --// method: returns a tuple of hue, saturation and value data
- function toHSV()
- local R,G,B = self.r*100,self.g*100,self.b*100
- local R,G,B = 128,0,128
- local Rp = R/255
- local Gp = G/255
- local Bp = B/255
- local Cmax = math.max(Rp, Gp, Bp)
- local Cmin = math.min(Rp, Gp, Bp)
- local delta = Cmax - Cmin
- local H
- if delta == 0 then
- H = 0
- elseif Cmax == Rp then
- H = 60* (((Gp - Bp)/delta)%6 )
- elseif Cmax == Gp then
- H = 60* (((Bp - Rp)/delta) + 2 )
- elseif Cmax == Bp then
- H = 60* (((Rp - Gp)/delta) + 4 )
- end
- local S
- if Cmax == 0 then
- S = 0
- end
- if Cmax ~= 0 then
- S = delta/ Cmax *100
- end
- local V = math.floor(Cmax*100)
- return H,S,V
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement