Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --# README
- --[[
- Author: Anatoly
- License: ISC
- Description: Color()s is a function that helps you accessing all the colors very easily.
- Thread: https://codea.io/talk/discussion/10043/colors
- Release: 3
- Changes:
- * warm-white
- * cold-white
- * white-10 to white-90 now support prerixes. e.g. reddish-white-10 to reddish-white-90 are shades of red
- * first version of the search box out! open in the output panel to searc for colors. Not working yet, but some values can be already searched through!
- * Fast access functions Fill(), Stroke(), Tint()
- * New color instances: "seablue", "bronze", "silver", "gold", "diamondblue", "gray" and "grey" (= white-50)
- ]]
- --# Colors
- _colors = {}
- -- <COLOR>
- colors1 = {}
- -- Primary & Secondary Colors
- colors1["red"] = color(255, 0, 0, 255)
- colors1["yellow"] = color(255, 255, 0, 255)
- colors1["green"] = color(0, 255, 0, 255)
- colors1["cyan"] = color(0, 255, 255, 255)
- colors1["blue"] = color(0, 0, 255, 255)
- colors1["magenta"] = color(255, 0, 255, 255)
- -- White scale
- colors1["black"] = color(0, 255)
- colors1["white"] = color(255, 255)
- -- Generate Grey Scale
- for i = 1, 9 do
- colors1["white-" .. i .. "0"] = color(25.5 * i, 255)
- --table.insert(_colors, {n="white-" .. i .. "0",c=colors1["white-" .. i .. "0"]})
- end
- colors1["gray"] = colors1["white-50"] -- Support BE and AE
- colors1["grey"] = colors1["white-50"]
- -- White shades
- colors1["warm-white"] = color(219, 211, 187, 255)
- colors1["cold-white"] = color(192, 212, 225, 255)
- -- Tertiary Colors
- --colors1["middlegreen"] = color(150, 155, 0, 255)
- colors1["grassgreen"] = color(150, 255, 0, 255)
- colors1["forestgreen"] = color(0, 155, 0, 255)
- colors1["turquoise"] = color(0, 255, 150, 255)
- colors1["skyblue"] = color(0, 150, 255, 255)
- colors1["seablue"] = color(50, 200, 255)
- colors1["orange"] = color(255, 150, 0, 255)
- colors1["rosa"] = color(255, 0, 150, 255)
- colors1["purple"] = color(150, 0, 255, 255)
- colors1["violet"] = colors1["purple"]
- colors1["pink"] = color(255, 150, 255, 255)
- colors1["bronze"] = color(190, 155, 90, 255)
- colors1["silver"] = color(180, 210, 210, 255)
- colors1["gold"] = color(225, 180, 60, 255)
- colors1["diamondblue"] = color(95, 170, 225, 255)
- -- Quartiary Colors
- --[[
- colors1["orange"] = color(255, 150, 255, 255)
- colors1["orange"] = color(150, 255, 150, 255)
- colors1["orange"] = color(150, 150, 255, 255)
- ]]
- colors2 = {}
- -- Generate Dark & Light Versions.
- for a, b in pairs(colors1) do
- colors2[a] = b
- colors2["dark-" .. a] = b:mix(color(0, 255), 0.5)
- colors2["light-" .. a] = b:mix(color(255, 255), 0.5)
- colors2["middle-" .. a] = b:mix(color(127, 255), 0.5)
- colors2["invert-" .. a] = color(255-b.r, 255-b.g, 255-b.b, 255)
- colors2["reddish-" .. a] = b:mix(color(255, 0, 0, 255), 0.6)
- colors2["greenish-" .. a] = b:mix(color(0, 255, 0, 255), 0.6)
- colors2["blueish-" .. a] = b:mix(color(0, 0, 255, 255), 0.6)
- table.insert(_colors, {n=a,c=b})
- for c, d in ipairs({"dark", "middle", "light", "reddish", "greenish", "blueish"}) do
- table.insert(_colors, {n=d.."-"..a,c=colors2[d.."-"..a]})
- end
- end
- colors3 = colors2
- -- <EARLIER>Invert all possible colors</EARLIER>
- --[[for a, b in pairs(colors2) do
- colors3[a] = b
- --colors3["invert-" .. a] = color(255-b.r, 255-b.g, 255-b.b, 255)
- --table.insert(_colors, {n="invert-"..a,c=colors3["invert-"..a]})
- end]]
- -- Export
- colors = colors3
- colors1 = nil
- colors2 = nil
- colors3 = nil
- -- Sort alphabetically.
- table.sort(_colors, function(a, b)
- return a.n < b.n
- end)
- -- </COLOR>
- -- Initialise
- Hex = function(l)
- if not (type(l) == "string") then
- assert(false, "bad argument #1 to 'Hex' (string expected, got ".. type(l) ..")")
- end
- local col = tonumber(l, 16)
- local b = col%256
- local g = ((col - b)/256)%256
- local r = ((col - g - b)/256^2)
- return color(r, g, b, 255)
- end
- Color = function(s, alpha)
- local c = color(0, 255)
- if not (type(s) == "string") then
- assert(false, "bad argument #1 to 'Color' (string expected, got ".. type(s) ..")")
- end
- s = string.lower(s)
- if colors[s] then c = colors[s] end
- if string.sub(s, 1, 1) == "#" and #s > 1 then c = Hex(string.sub(s, 2, #s)) end
- if alpha then c.a = alpha end
- return c
- end
- -- Fast access implementations
- function Fill(s, a) fill(Color(s, a)) end
- function Stroke(s, a) stroke(Color(s, a)) end
- function Tint(s, a) tint(Color(s, a)) end
- --# Main
- -- colors1
- function setup()
- displayMode(FULLSCREEN)
- parameter.text("SEARCH", "", search)
- --parameter.watch("1/DeltaTime")
- scrollY = 0
- scrollYAcc = 0
- scrollYAccMax = 100
- scrollYAccMin = -100
- touching = false
- infoState = 2
- infoVisibility = 0
- COLORS = _colors
- local __different = {}
- for a, b in pairs(colors) do
- local unique = true
- for c, d in ipairs(__different) do
- if d.r == b.r and d.g == b.g and d.b == b.b then
- unique = false
- end
- end
- if unique then
- table.insert(__different, b)
- end
- end
- print("There are " .. #__different .. " unique colors.")
- end
- function search(h)
- print(#_colors)
- c = {}
- for a, b in ipairs(_colors) do c[a]=b end
- if #h > 0 then
- r = 0
- for v = 1, #c do
- if v <= #c and (not string.find(c[v - r].n, h:gsub("%-", "%%-"))) then
- table.remove(c, v - r)
- r = r + 1
- elseif v > #c then
- break
- end
- end
- end
- COLORS = c
- print("SEARCH FOR '" .. h .. "' GAVE " .. #COLORS .. " RESULTS")
- end
- function showInfo()
- infoState = 1
- end
- function hideInfo()
- infoState = 2
- end
- function draw()
- displayRows = math.floor(HEIGHT/50)+3
- scrollY = scrollY + scrollYAcc
- if scrollYAcc < 1.5 and not touching then
- scrollYAcc = scrollYAcc + .05
- elseif touching then
- scrollYAcc = scrollYAcc * .8
- end
- if scrollYAcc > scrollYAccMax then
- scrollYAcc = scrollYAccMax
- elseif scrollYAcc < scrollYAccMin then
- scrollYAcc = scrollYAccMin
- end
- if scrollY > #COLORS * 50 + 100 then
- scrollY = -HEIGHT
- scrollYAcc = 2
- elseif scrollY < -HEIGHT then
- scrollY = -HEIGHT
- scrollYAcc = 0
- showInfo()
- end
- if scrollY > 100-HEIGHT then
- hideInfo()
- end
- if infoState == 1 and infoVisibility < 20 then
- infoVisibility = infoVisibility + 1
- elseif infoState == 2 and infoVisibility > 0 then
- infoVisibility = infoVisibility - 1
- end
- background(0)
- for a, b in ipairs(COLORS) do
- -- IGNORE IF OUTSIDE OF RANGE
- if (scrollY - 50 * a < 50 and HEIGHT - 50 * a + scrollY > -50) and b.c then
- -- BG
- strokeWidth(40)
- stroke(b.c or color(0, 255))
- line(50, HEIGHT - 50 * a + scrollY, WIDTH-50, HEIGHT - 50 * a + scrollY)
- -- TEXT
- strokeWidth(0)
- --<EARLIER>fill(colors["invert-"..b.n] or color(0, 0))</EARLIER>
- fill(0)
- if (b.c.r <= 50 and b.c.g <= 50 and b.c.b <= 50) then
- fill(255)
- end
- fontSize(40)
- font("CourierNewPS-BoldMT")
- text(b.n, WIDTH*.5, HEIGHT - 50 * a + scrollY)
- -- COMPARISERS
- for d, e in ipairs({"white", "white-50", "black", "red", "green", "blue"}) do
- fill(Color(e))
- ellipse(50 + (d-1) * 25, HEIGHT - 50 * a + scrollY, 20)
- end
- end
- end
- if infoVisibility > 0 then
- fill(Color("blueish-red", 255 * (infoVisibility / 20)))
- fontSize(100)
- font("MarkerFelt-Wide")
- text("Colors v3", WIDTH*.5, HEIGHT*.5)
- fill(Color("blueish-forestgreen", 255 * (infoVisibility / 20)))
- fontSize(50)
- font("Noteworthy-Light")
- text("Created by Anatoly.", WIDTH*.5, HEIGHT*.5-100)
- end
- end
- function touched(t)
- if t.state == BEGAN then
- touching = true
- elseif t.state == MOVING then
- scrollYAcc = scrollYAcc + t.deltaY *.2
- else -- END
- touching = false
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement