Jump to content




Choose background color


  • You cannot reply to this topic
2 replies to this topic

#1 vyse

  • Members
  • 45 posts

Posted 06 October 2014 - 05:40 PM

I am helping my friend with a program and we are wondering how you could make it were when you start the program you can select the background color.

#2 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 06 October 2014 - 06:38 PM

Well, you could do this
local color
repeat --#start a loop
  print( "choose a color" ) --#ask for a color
  color = read() --#get the color
until colors[ color ] --#if it is a valid color, exit the loop
term.setBackgroundColor( colors[ color ] ) --#set the background color


#3 YoYoYonnY

  • Members
  • 49 posts

Posted 06 October 2014 - 09:37 PM

Lets see how I'll do on my mobile phone
Original Version (Almost worked aswell )
Working version:
local function pickColor()
  local w, h = term.getSize()
  local left = math.floor(w/2)-2
  local top = math.ceil(h/2)-2
  local color = colors.white
  local colorPalet = window.create(term.current(),left-5,top,4,4,true)
  local colorPreview = window.create(term.current(),left+1,top,4,4,true)
  while true do
	term.setBackgroundColor(colors.white)
	term.clear()
	term.setCursorPos(1,1)
	term.setBackgroundColor(colors.red)
	term.setTextColor(colors.white)
	term.clearLine()
	term.setCursorPos(math.floor((w-12)/2),1)
	term.write("Pick a color")
	for x=1,4 do
	  for y=1,4 do
		colorPalet.setCursorPos(x,y)
		colorPalet.setBackgroundColor(2^((x-1)+(y-1)*4))
		colorPalet.write(" ")
	  end
	end
	colorPreview.setBackgroundColor(color)
	colorPreview.clear()
	term.setBackgroundColor(colors.red)
	term.setTextColor(colors.white)
	term.setCursorPos(left,top+6)
	term.write(" ok ")
	sEvent, param1, param2, param3 = os.pullEvent()
	if sEvent == "mouse_click" and param1 == 1 then
	  if param2 >= left-5 and param2 < left-1 then
		if param3 >= top and param3 < top+4 then
		  color = 2^((param2-left-7)+(param3-top+3)*4)
		end
	  end
	  if param2 >= left and param2 < left+4 and param3 == top+6 then
		return color
	  end
	end
  end
end
Lets hope this works. I might check tomorrow.

Edited by YoYoYonnY, 07 October 2014 - 02:51 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users