|
Post by warspyking on Nov 8, 2015 21:17:28 GMT
|
|
|
Post by leon26leon26 on Nov 8, 2015 22:23:58 GMT
Got something. This function allows you to combine 2 Colors to 1. Examples: combineColors(draw.green, draw.red, 0) --returns draw.green combineColors(draw.green, draw.red, 1) --returns draw.red combineColors(draw.green, draw.red, 0.35) --returns a mix of: 35% green and 65% red
Here the function, with some extras: function combineColors(color1, color2, level)
level = level * 100
--red reddiff = -1*(color1["red"] - color2["red"]) redpixel = reddiff / 100 print("Red difference: "..reddiff)
--blue bluediff = -1*(color1["blue"] - color2["blue"]) bluepixel = bluediff / 100 print("Blue difference: "..bluediff)
--green greendiff = -1*(color1["green"] - color2["green"]) greenpixel = greendiff / 100 print("Green difference: "..greendiff)
newred = color1["red"] + level * redpixel newblue = color1["blue"] + level * bluepixel newgreen = color1["green"] + level * greenpixel newcolor = {red=newred, blue=newblue, green=newgreen, alpha=1}
print("Red: "..newcolor["red"]) print("Blue: "..newcolor["blue"]) print("Green: "..newcolor["green"])
print("How to define in script:\nmyColor = {red=\""..newcolor["red"].."\", blue=\""..newcolor["blue"].."\", green=\""..newcolor["green"].."\"}")
return newcolor
end
combined = combineColors(draw.green, draw.blue, 0.3573)
draw.setscreen(1) draw.fillrect(0, 0, 320, 480, newcolor)
sleep(math.huge)
LOL I was the one who told you to add the number argument to that! I still have a "Gradient" script saved! get that lol out of your vocabulary, It's not 2012
|
|
|
Post by warspyking on Nov 9, 2015 0:19:27 GMT
LOL I was the one who told you to add the number argument to that! I still have a "Gradient" script saved! get that lol out of your vocabulary, It's not 2012 Nevah LOL FTW!
|
|
|
Post by lars on Nov 9, 2015 5:33:26 GMT
Got something. This function allows you to combine 2 Colors to 1. Examples: combineColors(draw.green, draw.red, 0) --returns draw.green combineColors(draw.green, draw.red, 1) --returns draw.red combineColors(draw.green, draw.red, 0.35) --returns a mix of: 35% green and 65% red
Here the function, with some extras: function combineColors(color1, color2, level)
level = level * 100
--red reddiff = -1*(color1["red"] - color2["red"]) redpixel = reddiff / 100 print("Red difference: "..reddiff)
--blue bluediff = -1*(color1["blue"] - color2["blue"]) bluepixel = bluediff / 100 print("Blue difference: "..bluediff)
--green greendiff = -1*(color1["green"] - color2["green"]) greenpixel = greendiff / 100 print("Green difference: "..greendiff)
newred = color1["red"] + level * redpixel newblue = color1["blue"] + level * bluepixel newgreen = color1["green"] + level * greenpixel newcolor = {red=newred, blue=newblue, green=newgreen, alpha=1}
print("Red: "..newcolor["red"]) print("Blue: "..newcolor["blue"]) print("Green: "..newcolor["green"])
print("How to define in script:\nmyColor = {red=\""..newcolor["red"].."\", blue=\""..newcolor["blue"].."\", green=\""..newcolor["green"].."\"}")
return newcolor
end
combined = combineColors(draw.green, draw.blue, 0.3573)
draw.setscreen(1) draw.fillrect(0, 0, 320, 480, newcolor)
sleep(math.huge)
LOL I was the one who told you to add the number argument to that! I still have a "Gradient" script saved! Yes, thanks for that I already published it as gradientC, but i updated something
|
|
|
Post by Tag365 on Nov 11, 2015 3:06:46 GMT
This one makes it so you can create colors which can be added like they were numbers.
local Color = {} Color.__index = Color -- failed table lookups on the instances should fallback to the class table, to get methods Color.classtype = "Color"
-- This function constructs a new object of this type. Color.new = function(red, green, blue, alpha, dontdivide) local self = setmetatable({}, Color) if dontdivide then self.red = red self.green = green self.blue = blue self.alpha = alpha or 1 else self.red = red/255 self.green = green/255 self.blue = blue/255 self.alpha = (alpha or 255)/255 end return self end
function Color:Invert() return Color.new(1 - self.red, 1 - self.green, 1 - self.blue, 1 - self.alpha, true) end
-- Adds a vector to this color. function Color.addColorToColor(self, vector2) local output = Color.new(self.red + vector2.red, self.green + vector2.green, self.blue + vector2.blue, self.alpha + vector2.alpha) return output end
-- Subtracts a vector from this vector. function Color.subtractColorFromColor(self, vector2) local output = Color.new(self.red - vector2.red, self.green - vector2.green, self.blue - vector2.blue, self.alpha - vector2.alpha) return output end
-- Multiplies a vector by this vector. function Color.multiplyColorByColor(self, vector2) local output = Color.new(self.red, self.green, self.blue, self.alpha) output.red = self.red * vector2.red output.green = self.green * vector2.green output.blue = self.blue * vector2.blue output.alpha = self.alpha * vector2.alpha return output end
-- Divides a vector by this vector. function Color.divideColorByColor(self, vector2) local output = Color.new(self.red, self.green, self.blue, self.alpha) output.red = self.red / vector2.red output.green = self.green / vector2.green output.blue = self.blue / vector2.blue output.alpha = self.alpha / vector2.alpha return output end
-- Returns the raw values for this color. function Color.raw(self) return self.red, self.green, self.blue, self.alpha end
-- Set up metatables Color.__tostring = function(self) return self.red..", "..self.green..", "..self.blue..", "..self.alpha end Color.__add = function(self, other) if GetObjectType(other) ~= "Color" then if type(other) == "number" then return Color.new((self.red*255) + other, (self.green*255) + other, (self.blue*255) + other, (self.alpha*255)) end return self end return self:addColorToColor(other) end Color.__sub = function(self, other) if GetObjectType(other) ~= "Color" then if type(other) == "number" then return Color.new((self.red*255)-other, (self.green*255)-other, (self.blue*255)-other, (self.alpha*255)) end return self end return self:subtractColorFromColor(other) end Color.__mul = function(self, other) if GetObjectType(other) ~= "Color" then if type(other) == "number" then return Color.new(self.red*other, self.green*other, self.blue*other, self.alpha, true) end return self end return self:multiplyColorByColor(other) end Color.__div = function(self, other) if GetObjectType(other) ~= "Color" then if type(other) == "number" then return Color.new((self.red)/other, (self.green)/other, (self.blue)/other, self.alpha, true) end return self end return self:divideColorByColor(other) end
Color.__eq = function(self, other) if GetObjectType(other) ~= "Color" then return false end if self.red == other.red and self.green == other.green and self.blue == other.blue then return true end return false end Color.__lt = function(self, other) if GetObjectType(other) ~= "Color" then return false end if self.red < other.red and self.green < other.green and self.blue < other.blue then return true end return false end Color.__le = function(self, other) if GetObjectType(other) ~= "Color" then return false end if self.red <= other.red and self.green <= other.green and self.blue <= other.blue then return true end return false end
if not GetObjectType then local oldType = type function GetObjectType(object) if oldType(object) == "table" then return object.classtype or object.__classtype or object.__type or "table" end return oldType(object) end type = GetObjectType end
-- Enhance default draw colors table for k, v in pairs(draw) do if type(v) == "table" then if v.red then draw[k] = Color.new(v.red, v.green, v.blue, v.alpha, true) Color[k] = draw[k] end end end
return Color
|
|
|
Post by warspyking on Nov 11, 2015 4:37:02 GMT
Awesome
|
|