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

Openperipherals addBox() colors

Started by flaghacker, 24 March 2014 - 10:22 AM
flaghacker #1
Posted 24 March 2014 - 11:22 AM
I'm trying to make something with the terminal glasses from openperipherals, but I don't understand how the colours work. I thought the colours were in hexadecimal, so I look it up on the internet and I founded this site: http://www.2createaw...rs.html#hextool.

My code is like this:

glass = peripheral.wrap("right")
glass.clear()
glass.addBox(0,0,100,420,0d0082,1)
And it says this, no matter what colour I try (unless it's 0x00000):

For input string: "0d0082"

Is it maybe not in hexadecimal?

Also, does anyone knows what the screen with and length and height are? (I try to figure it out using something like this, but that isn't very precise:

glass = peripheral.wrap("right")
local x = 0
local running = true

glass.clear()

while running do
	timer = os.startTimer(0.01)
	a = os.pullEvent()
	if a == "key" then
		running = false
		print(x)
	else
		x = x + 1
		glass.addBox(0,0,100,x,0x000000,1)
	end
end
henrykvdb #2
Posted 24 March 2014 - 04:31 PM
I tried the same thing and I ran in the same problem anyone knows what we are doing wrong? I really want to know because then I will be able to finish my computercraft program
Inumel #3
Posted 24 March 2014 - 06:12 PM
I have noticed this as well, it has to do with the letters in it. You need to find a code thats completely numbers
CometWolf #4
Posted 24 March 2014 - 06:14 PM
you need the "0x" part in the color code, that's why 0x000000 works. Also, don't pass it as a string, just pass it right in like a number. It's been a while since i worked with the glasses, but i believe they added a method to get the screen size. Check the bridge docs. It's dependent on the resolution the game is running in, so there's no definitive answer.
Edited on 24 March 2014 - 05:16 PM
flaghacker #5
Posted 24 March 2014 - 07:31 PM
Now I'm trying to run this function:

glass.addGradientBox(1,1,200,200,0x08916,1,0x0a3a3,1,1)
And it does nothing!
Syntax should be:

addGradientBox(x, y, height, witdh, color1, opacity1, color2, opacity2, direction)
direction:
1 = vertical
2 = horizontally

And how do you change the resolution of your game? Because I'm trying to make something for a few friends, and we as all have different resolutions… So I would have to set up the graphics for each individual player… It's there a way we can ask set our games to the same resolution?
theoriginalbit #6
Posted 24 March 2014 - 11:17 PM
that is an invalid HEX code. valid codes

0xRRGGBB

or

0xRGB

note how its 3 or 6, not 5 like you have.

EDIT: as for the resolution question, yeah each of you can resize your window to the same size. we were looking into a way to have the clients send the screen size to the server on request so that you can get the size of specific users screens, but its a little difficult so hasn't been implemented yet.
Edited on 24 March 2014 - 10:19 PM
flaghacker #7
Posted 25 March 2014 - 06:23 AM
Are these colors related to RGB? I guess you take your RGB-code and convert it to hexadecimal?
theoriginalbit #8
Posted 25 March 2014 - 06:35 AM
indeed they do relate, that's why I put them there.

0xRRGGBB

RR is 00-FF for Red
GG is 00-FF for Green
BB is 00-FF for Blue

00-FF is hexadecimal for 0-255 which is the number range that RGB colours use.

a little while ago now I did make a function you could use to convert RGB into a valid colour for OpenPeripheral

local function rgb( _r, _g, _b )
  return bit.bor( bit.blshift( bit.bor( bit.blshift( _r, 8 ), _g ), 8 ), _b )
end
but obviously using the above is not as efficient as just using the correct value to begin with; although given how computers work the above code isn't exactly inefficient, but it is inefficient to perform operations compared to declaring a static number.

EDIT: Good website to get different colour values off. http://www.colorhexa.com
Edited on 25 March 2014 - 05:39 AM
flaghacker #9
Posted 25 March 2014 - 09:39 AM
Thank you very mush, I think I'm going to use your function to do one-time conversations between RGB and hexadecimal, and then save it as a static value.

I have only one question left: Where exactly do you change Minecraft's resolution?
theoriginalbit #10
Posted 25 March 2014 - 10:06 AM
no problems. if you do know the RGB you could use colorhexa.com to convert to HEX.

as I said in my previous reply, you don't. you'll have to use some other program (or a setting in Windows maybe?) to set the size of the Minecraft window and make all your friends do the same.