Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0
maideniles

Help with colors in an Lua program

Question

Hi, All!  I'm brand new here, and I'm a complete beginner with Lua, so please bear with me.  :D  

My son and I are building an airport, and I, ever the overachiever, decided I want to make it fancy.  I am attempting to make screens that display flight information, similar to what you would see in an airport.  Here's an example of how I would like for it to appear:

 

                                Arrivals                                              --  ALL text would be white
                                                                                                                          
Airline          Flight      Arriving From        Gate     Status   --  This line, the background would be dark blue
                                                                                            
Delta            1427     Nashville, TN         B8       On Time  -- This line, the background would be blue 
                                                                                            
Southwest     632      Phoenix, AZ           A5       Delayed  --  This line, the background would be light blue
 
 

I have the basic program written, and it works.  But it's so plain...it needs some flair! B)  

Unfortunately, the only way I can figure out how to add color to it is to change the foreground/background colors in the gpu. And that doesn't change line by line, just the whole thing... and it resets if the system is rebooted :(.

 

So, Here I am...Please help me make our Airport awesome!  

 

The code is basically like this, only the arrays are much bigger:  (And I apoligize for redundancy and/or noob mistakes in the code...As I said, I'm brand new to Lua.  Suggestions are welcome.  :)

math.randomseed(os.time())


Airline = {"Delta            ", "American Airlines", "Southwest        "}
Flight = math.random(100,2000)
Arrival = {"Nashville, TN ", "Chicago, IL  ", "Phoenix, AZ  ", "Dallas, TX   "}
Gate = {"A", "B"}
Number = math.random(1,8)
Time = math.random(0100,2400)
Status = {"  On Time", "Delayed ", "Cancelled"}

print("                    Arrivals                    ")

print(" ")

print(" Airline              Flight    Arriving From    Gate    Time    Status")

print(" ")
print(" " .. Airline[math.random(1,#Airline)] .. "     " .. Flight .. "     " .. Arrival[math.random(1,#Arrival)].. "      " .. Gate[math.random(1,#Gate)] .. Number .. "    " .. Time .. "      " .. Status[math.random(1,#Status)].. " ")

Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0

I have no idea how to implement color mid-print but color is achieved by these commands

EDIT: Remember that you have to do the gpu getting at the first lines of the program(before anything else happens in the code)

--Get GPU
local c = require("component")
local gpu = c.gpu
--Set Foreground(text color), or Background(Background color)
--Background color only changes for the places BEHIND THE TEXT PRINTED AFTER THIS
gpu.setForeground(0x444444) - set text to gray
gpu.setBackground(0x33DBFF) - set background to light blue
Link to post
Share on other sites
  • 0
On 10/30/2016 at 11:27 AM, JuhaJGamer said:

I have no idea how to implement color mid-print but color is achieved by these commands

EDIT: Remember that you have to do the gpu getting at the first lines of the program(before anything else happens in the code)


--Get GPU
local c = require("component")
local gpu = c.gpu
--Set Foreground(text color), or Background(Background color)
--Background color only changes for the places BEHIND THE TEXT PRINTED AFTER THIS
gpu.setForeground(0x444444) - set text to gray
gpu.setBackground(0x33DBFF) - set background to light blue

This was my test result by changing the background color then writing the text, changing the cursor position, and repeating. I don't know exactly how you would go about this over the whole screen, but i hope this helps

local gpu = require("component").gpu
local term = require("term")
--cursor is already set a (1,1), no need to change anything if you don't want to
gpu.setBackground(0x003d99) -- example dark blue
term.write("Insert your stuff here, this is basically like the print function except no auto indenting!") -- color should be different BEHIND the text here
term.setCursor(1,3) -- Moves cursor down a bit
gpu.setBackground(0x005ce6) -- Normal Blue
term.write("yada yada") --only should be color behind the text
term.setCursor(1,4) -- this is what made mine connect for some reason
gpu.setBackground(0x66a3ff) --Lighter blue
term.write("You get the idea") -- only color behind the text

Hope this helps!

2016-12-28_21.36.20.png

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.