Posted 08 July 2013 - 12:31 AM
Easy Color API (Version: 1.2)
(MC Version: 1.4.7/1.5.2)
(CC Version: 1.5+)
Have you ever had trouble setting colors in your programs because it is long and tedious work? Well this API can cut down that time easily. The Color API is useful for flashing colors or creating cool UI's. Set your text color and background. Even give your whole screen a background. This simple to use API is for the people who want the complicated simplified. The lazy to actually have some fun making programs. This will change how you use colors on both your Advanced Monitors and Advanced Computers. Now that I told you about the API. How about i give an explanation of how it works.
Get the code here:
pastebin get GifVQDx4 color
New Functions:
color.setBG("string color", "string type")
color.setTC("string color", "string type")
color.fill("string color", "string type")
color.cable("string color", "string side", "string state")
What parts mean:
"string color" is any of the 16 colors from white to black. It is in the same order as the colored wool in the game.
"string type" is to choose the certain type of device it will display to.
There are two types of devices, Monitors and Computers.
Monitors are represented with the string "mon".
Computers are represented with the string "comp".
"string side" is the side of the computer it will output a cable signal.
"string state" is what sets the state of the wire being "on" or "off".
Video:
[media]http://www.youtube.com/watch?v=pXizUIA7SlY&feature=share&list=UUradvC7Oc20T-viGoS4mtOw[/media]
[media]http://youtu.be/QcJYnVZIGNg[/media]
Code:
m = peripheral.wrap("right")
--color it reads to select which color to use
local co = {"white","orange","magenta","lightBlue",
"yellow","lime","pink","grey",
"lightGrey","cyan","purple","blue",
"brown","green","red","black"}
--using the colors api to set the color in other commands
local co2 = {colors.white, colors.orange,
colors.magenta, colors.lightBlue,
colors.yellow, colors.lime,
colors.pink, colors.grey,
colors.lightGrey, colors.cyan,
colors.purple, colors.blue,
colors.brown, colors.green,
colors.red, colors.black}
--Example: color.setBG("red", "comp")
function setBG(color,type)
if type == "mon" then
for i = 1, 16 do
if co[i] == color then
m.setBackgroundColor(co2[i])
end
end
elseif type == "comp" then
for i = 1, 16 do
if co[i] == color then
term.setBackgroundColor(co2[i])
end
end
else
print("That is NOT a the right type.")
end
end
--Example: color.setTC("purple", "mon")
function setTC(color, type)
if type == "mon" then
for i = 1, 16 do
if co[i] == color then
m.setTextColor(co2[i])
end
end
elseif type == "comp" then
for i = 1, 16 do
if co[i] == color then
term.setTextColor(co2[i])
end
end
else
print("That is not the right type!!!")
end
end
--color.fill is to be used as a base background.
--Use it before you print your text, or else it
--will cover it up.
--Example fill : color.fill("cyan", "mon")
--then add text: color.setTC("black", "mon")
function fill(color, type)
if type == "mon" then
for i = 1, 16 do
if co[i] == color then
m.setBackgroundColor(co2[i])
m.clear()
end
end
elseif type == "comp" then
for i = 1, 16 do
if co[i] == color then
term.setBackgroundColor(co2[i])
term.clear()
end
end
else
print("That is not the right type")
end
end
--Example: color.cable("red","right","on")
function cable(color, side, state)
if state == "on" then
for i = 1, 16 do
if co[i] == color then
rs.setBundledOutput(side, co2[i])
end
end
elseif state == "off" then
for i = 1, 16 do
if co[i] == color then
rs.setBundledOutput(side, 0)
end
end
end
end
If there is an addition you want, I may be able to add it.
If there is any problem, PM me on Computer Craft forums, Minecraft forums, youtube or follow me on twitter @wolfhowl42
Edited on 08 July 2013 - 08:38 PM