This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
wolfhowl42's profile picture

[MC 1.4.7/1.5.2][CC 1.5+] Easy Color API

Started by wolfhowl42, 07 July 2013 - 10:31 PM
wolfhowl42 #1
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
Zudo #2
Posted 08 July 2013 - 03:13 AM
Sorry, but what does "string type" do?
wolfhowl42 #3
Posted 08 July 2013 - 07:17 AM
the "string type" is what selects between using the computer or monitor. if you choose the type "mon", you will display on the monitor. If you use the type "comp", it displays to the computer.
Dave-ee Jones #4
Posted 29 July 2013 - 04:00 AM
You should probs change that to Peripheral type or per instead…I got really confused until I saw what they were supposed to be…("mon","comp")
bentallea #5
Posted 23 August 2013 - 01:06 AM
what if the monitor is not on the right? would I just change the direction?