Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os = require("os")
- component = require("component")
- local io = require("io")
- file_in = io.open("input2.txt", "r")
- file_data = file_in:read("*all")
- file_in:close()
- gpu1 = component.proxy(component.get("c295"))
- screen = component.proxy(component.get("3bc7"))
- gpu1.bind(screen.address)
- function ssplit (inputstr, sep)
- if sep == nil then
- sep = "%s"
- end
- local t={}
- for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
- table.insert(t, str)
- end
- return t
- end
- function get_colour(r_char, g_char, b_char)
- r = math.floor(((string.byte(r_char) - string.byte("!"))/94)*255)
- g = math.floor(((string.byte(g_char) - string.byte("!"))/94)*255)
- b = math.floor(((string.byte(b_char) - string.byte("!"))/94)*255)
- combined = (r << 16) + (g << 8) + b
- -- print(r, g, b, combined)
- return combined
- end
- function draw_image(to_draw)
- file_sections = ssplit(to_draw, " ")
- image_width = tonumber(file_sections[1])
- data = file_sections[2]
- image_height = string.len(data)/image_width/3
- print(image_width, image_height)
- print(string.len(data))
- -- gpu1.setActiveBuffer(1)
- for y=0,image_height-1,2 do
- for x=0, image_width-1 do
- top_colour_r = y * image_width * 3 + (x*3) + 1
- bottom_colour_r = (y+1) * image_width * 3 + (x*3) + 1
- -- print(top_colour_r)
- colour = get_colour(string.sub(data, top_colour_r, top_colour_r), string.sub(data, top_colour_r+1, top_colour_r+1), string.sub(data, top_colour_r + 2, top_colour_r + 2))
- gpu1.setForeground(colour)
- if bottom_colour_r < string.len(data) then
- colour2 = get_colour(string.sub(data, bottom_colour_r, bottom_colour_r), string.sub(data, bottom_colour_r+1, bottom_colour_r+1), string.sub(data, bottom_colour_r + 2, bottom_colour_r + 2))
- gpu1.setBackground(colour2)
- end
- gpu1.set(x, y/2, "▀")
- end
- end
- end
- -- draw_image(file_data)
Add Comment
Please, Sign In to add comment