Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- print("Text to draw : ")
- -- text = read()
- speed = 0.1
- marge = 3
- screen = peripheral.wrap("left")
- debug = peripheral.wrap("bottom")
- width, height = screen.getSize()
- function debug_write(text,line)
- debug.setCursorPos(1,line)
- debug.write(text)
- end
- start_char = {"/", "|", "\\"}
- end_char = {"\\", "|", "/"}
- function generate_center_text(text, pos_y, dir)
- return {
- content=text,
- pos={x=-#text, y=pos_y or height/2},
- direction = dir or "none",
- borne={min=4,max=30}
- }
- end
- function draw_cadre(text_pos, text_w)
- start_height = text_pos.y - 1
- for h=0,2,1 do
- new_line = ""
- new_line = start_char[h+1]..new_line
- for w=1,text_w,1 do
- new_line = new_line.."-"
- end
- new_line = new_line..end_char[h+1]
- screen.setCursorPos(text_pos.x-1, start_height+h)
- screen.write(new_line)
- end
- end
- function update_text_pos(text)
- -- debug_write(text.borne.min.."/"..text.borne.max, 1)
- debug_write(text.pos.x < text.borne.max and text.direction == "right",1)
- debug_write(text.direction, 2)
- debug_write(text.pos.x,3)
- debug_write(text.borne.max,4)
- if text.direction ~= "none" then
- if text.direction == "right" then
- if text.pos.x < text.borne.max then
- text.pos.x = text.pos.x + 1
- else
- text.direction = "left"
- end
- elseif text.direction == "left" then
- if text.pos.x > text.borne.min then
- text.pos.x = text.pos.x - 1
- else
- text.direction = "right"
- end
- end
- else
- print(text.content.."ne bouge pas")
- end
- end
- function draw_text(text_obj)
- f_pos = {
- x=text_obj.pos.x - #text_obj.content/2,
- y=text_obj.pos.y - 1
- }
- draw_cadre(f_pos, #text_obj.content)
- screen.setCursorPos(f_pos.x, f_pos.y)
- screen.write(text_obj.content)
- end
- -- list = {"Salut", "Les", "P'tits", "Amis"}
- -- text_list = {}
- -- for i=1,#list,1 do
- -- table.insert(text_list, generate_center_text(list[i], i*marge, "right", 40))
- -- end
- text = generate_center_text("Salut", 3, "right")
- while true do
- screen.clear()
- update_text_pos(text)
- draw_text(text)
- sleep(speed)
- end
Add Comment
Please, Sign In to add comment