Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- 26 x 20
- local cobalt = dofile("cobalt/init.lua")
- local graph = cobalt.graphics
- local str = ""
- local floor, max, min, sqrt = math.floor, math.max, math.min, math.sqrt
- local t = os.time()
- local h = math.floor(t)
- local mt = (t - h) * 60
- local m = math.floor(mt)
- local t0 = 0
- local stars = {}
- local starCount = 20
- local debug = ""
- local phases = {[0] = "Full Moon", "Waning Gibbous", "Third Quarter", "Waning Crescent", "New Moon", "Waxing Crescent", "First Quarter", "Waxing Gibbous"}
- local constel = {
- ["Discidia"] = {
- type = "Offense",
- light = 2,
- days = {0, 1, 2, 3, 7}
- },
- ["Evorsio"] = {
- type = "Destruction",
- light = 2,
- days = {3, 4, 5, 6, 7}
- },
- ["Armara"] = {
- type = "Defense",
- light = 2,
- days = {0, 4, 5, 6, 7}
- },
- ["Aevitas"] = {
- type = "Creation",
- light = 2,
- days = {0, 1, 4, 5, 6, 7}
- },
- ["Vicio"] = {
- type = "Motion",
- light = 2,
- days = {0, 4, 5, 6, 7}
- },
- ["Pelotrio"] = {
- type = "Convocation",
- light = 1,
- days = {}
- },
- ["Lucerna"] = {
- type = "Light",
- light = 1,
- days = {0, 1, 2, 3, 4}
- },
- ["Mineralis"] = {
- type = "Mineral",
- light = 1,
- days = {3, 4, 5, 6, 7}
- },
- ["Fornax"] = {
- type = "Heat",
- light = 1,
- days = {1, 2, 3, 4, 5}
- },
- ["Bootes"] = {
- type = "Herding",
- light = 1,
- days = {0, 1, 2, 3, 4}
- },
- ["Octans"] = {
- type = "Light",
- light = 1,
- days = {3, 4, 5, 6, 7}
- },
- ["Ulteria"] = {
- type = "???",
- light = 0,
- days = {}
- },
- ["Vorux"] = {
- type = "???",
- light = 0,
- days = {}
- },
- ["Gelu"] = {
- type = "???",
- light = 0,
- days = {}
- },
- ["Alcara"] = {
- type = "???",
- light = 0,
- days = {}
- },
- ["Horologium"] = {
- type = "???",
- light = 0,
- days = {}
- }
- }
- local function contains(t, i)
- for j = 1, #t do
- if t[j] == i then
- return true
- end
- end
- return false
- end
- local function getConstellations(phase)
- local out = {}
- local names = {}
- for name, t in pairs(constel) do
- if contains(t.days, phase) then
- out[name] = t
- names[#names + 1] = name
- end
- end
- return out, names
- end
- function cobalt.load()
- for i = 1, starCount do
- stars[i] = {
- (20 + 8 * math.random()) % 24,
- 7 + 8 * math.random(),
- 7 + 8 * math.random()
- }
- end
- end
- function cobalt.update()
- t = os.time()
- h = math.floor(t)
- mt = (t - h) * 60
- m = math.floor(mt)
- t0 = (t0 + 0.1) % 24
- end
- local function star(t, targetAngle, rx, ry)
- local st = -((targetAngle - t) / 12 + 0.5) * math.pi
- local stx = math.floor(13 + rx * math.cos(st) + 0.5)
- local sty = math.floor(10 + ry * math.sin(st) + 0.5)
- if sty <= 5 then
- graph.setBackgroundColor("brown")
- graph.setColor("white")
- graph.print(".", stx, sty)
- end
- end
- local function rect(x, y, w, h)
- for i = x, x + w - 1 do
- for j = y, y + h - 1 do
- graph.pixel(i, j)
- end
- end
- end
- local function mainScreen()
- term.setPaletteColour(colors.yellow, 0xfffa91)
- term.setPaletteColour(colors.gray, 0x333333)
- term.setPaletteColour(colors.lightGray, 0x3d3d3d)
- term.setPaletteColour(colors.lightBlue, 0x86b2ff)
- term.setPaletteColour(colors.orange, 0xf2ac29)
- term.setPaletteColour(colors.brown, 0x151b40)
- term.setPaletteColour(colors.pink, 0xe9eff5)
- term.setPaletteColour(colors.purple, 0xd1d1d1)
- term.setPaletteColour(colors.magenta, 0x9c9c9c)
- graph.setBackgroundColor("gray")
- graph.setColor("brown")
- graph.rect("fill", 0, 0, 25, 20)
- local scale = 1
- local t = (os.time() * scale) % 24
- local eS = 18.5
- local eE = 19.75
- local dS = 4.75
- local dE = 6
- for i = 1, starCount do
- star(t, stars[i][1], stars[i][2], stars[i][3])
- end
- for i = -12, 13 do
- for j = 0, 12 do
- local a = math.atan2(j, i)
- local duskMinA = ((eS - t) / 12 + 0.5) * math.pi
- local duskMaxA = ((eE - t) / 12 + 0.5) * math.pi
- local dawnMinA = ((dS - t) / 12 + 0.5) * math.pi
- local dawnMaxA = ((dE - t) / 12 + 0.5) * math.pi
- local L = math.sqrt(0.25 * i * i + j * j)
- if a >= duskMinA and a <= duskMaxA or a >= dawnMinA and a <= dawnMaxA then
- graph.setColor("orange")
- graph.pixel(12 + i, 12 - j)
- elseif a <= duskMaxA and a >= dawnMinA then
- graph.setColor("lightBlue")
- graph.pixel(12 + i, 12 - j)
- end
- end
- end
- local sun = -((12 - t) / 12 + 0.5) * math.pi
- local sunx = math.floor(13 + 17 * math.cos(sun) + 0.5)
- local suny = math.floor(10 + 8 * math.sin(sun) + 0.5)
- graph.setColor("yellow")
- graph.pixel(sunx , suny )
- graph.pixel(sunx -1, suny)
- graph.pixel(sunx +1, suny)
- graph.pixel(sunx , suny -1)
- graph.pixel(sunx -1, suny-1)
- graph.pixel(sunx +1, suny-1)
- local moon = -(0.5 - t/12) * math.pi
- local moonx = math.floor(13 + 17 * math.cos(moon) + 0.5)
- local moony = math.floor(10 + 8 * math.sin(moon) + 0.5)
- graph.setColor("pink")
- graph.pixel(moonx , moony )
- graph.pixel(moonx -1, moony)
- graph.pixel(moonx +1, moony)
- graph.pixel(moonx , moony -1)
- graph.pixel(moonx -1, moony-1)
- graph.pixel(moonx +1, moony-1)
- graph.setColor("gray")
- -- graph.print("|", 12, 0)
- -- graph.print("|", 12, 1)
- -- graph.print("|", 12, 2)
- -- graph.print("|", 12, 3)
- -- graph.print("|", 12, 4)
- -- graph.print("|", 12, 5)
- graph.setBackgroundColor(colors.lightBlue)
- graph.setColor("lightGray")
- for j = 0, 5 do
- local a = math.atan2(12-j, 0)
- local duskMinA = ((eS - t) / 12 + 0.5) * math.pi
- local duskMaxA = ((eE - t) / 12 + 0.5) * math.pi
- local dawnMinA = ((dS - t) / 12 + 0.5) * math.pi
- local dawnMaxA = ((dE - t) / 12 + 0.5) * math.pi
- graph.setBackgroundColor("brown")
- if 12 >= sunx - 1 and 12 <= sunx + 1 then
- if j >= suny - 1 and j <= suny then
- graph.setBackgroundColor(colors.yellow)
- else
- if a >= duskMinA and a <= duskMaxA or a >= dawnMinA and a <= dawnMaxA then
- graph.setBackgroundColor(colors.orange)
- elseif a <= duskMaxA and a >= dawnMinA then
- graph.setBackgroundColor(colors.lightBlue)
- end
- end
- elseif 12 >= moonx - 1 and 12 <= moonx + 1 then
- if j >= moony - 1 and j <= moony then
- graph.setBackgroundColor(colors.pink)
- else
- if a >= duskMinA and a <= duskMaxA or a >= dawnMinA and a <= dawnMaxA then
- graph.setBackgroundColor(colors.orange)
- elseif a <= duskMaxA and a >= dawnMinA then
- graph.setBackgroundColor(colors.lightBlue)
- end
- end
- else
- if a >= duskMinA and a <= duskMaxA or a >= dawnMinA and a <= dawnMaxA then
- graph.setBackgroundColor(colors.orange)
- elseif a <= duskMaxA and a >= dawnMinA then
- graph.setBackgroundColor(colors.lightBlue)
- end
- end
- graph.print("|", 12, j)
- end
- graph.setBackgroundColor(colors.gray)
- graph.setColor("gray")
- graph.ellipse("fill", 0, 6, 25, 6)
- graph.rect("fill", 0, 10, 25, 12)
- graph.setColor("lightGray")
- graph.pixel(0, 8)
- graph.pixel(1, 8)
- graph.line(2, 7, 5, 7)
- graph.line(6, 6, 18, 6)
- graph.line(19, 7, 22, 7)
- graph.pixel(23, 8)
- graph.pixel(24, 8)
- graph.setColor("white")
- graph.print(string.format("%02d", h) .. ":" .. string.format("%02d", m), 10, 8)
- local phase = (os.day() - 1) % 8
- graph.setColor("purple")
- graph.print("Tonight's Moon:", 2, 10)
- graph.setColor("magenta")
- graph.print("- " .. phases[phase] .. " >>", 2, 11)
- graph.setColor("purple")
- graph.print("Constellations:", 2, 13)
- local list, names = getConstellations(phase)
- graph.setColor("magenta")
- for i = 1, math.min(#names, 4) do
- if #names == math.min(#names, 4) and i == 4 then
- graph.print(" - " .. names[i] .. " >>", 2, 13 + i)
- else
- graph.print(" - " .. names[i], 2, 13 + i)
- end
- end
- if #names - 4 > 0 then
- graph.print("and " .. (#names - 4) .. " more >>", 2, 13 + math.min(#names, 4) + 1)
- end
- end
- local function moonScreen()
- term.setPaletteColour(colors.gray, 0x3d3d3d)
- term.setPaletteColour(colors.purple, 0x333333)
- term.setPaletteColour(colors.pink, 0x0e1423)
- term.setPaletteColour(colors.lightGray, 0x60697d)
- term.setPaletteColour(colors.cyan, 0x9ba5bd)
- term.setPaletteColour(colors.blue, 0x2b2f38)
- graph.setBackgroundColor("purple")
- graph.setColor("purple")
- rect(0, 0, 25, 20)
- graph.setColor("gray")
- rect(5, 1, 13, 9)
- graph.setColor("pink")
- rect(6, 2, 11, 7)
- local daysUntilSolar = 36 - (os.day() - 9) % 36
- local phase = (os.day() - 1) % 8
- if phase == 0 then
- graph.setColor("cyan")
- rect(6, 2, 11, 7)
- graph.setColor("lightGray")
- rect(15, 2, 2, 7)
- rect(6, 8, 11, 1)
- elseif phase == 1 then
- graph.setColor("cyan")
- rect(6, 2, 5, 7)
- rect(11, 3, 1, 5)
- rect(12, 4, 1, 3)
- graph.setColor("lightGray")
- rect(6, 7, 5, 2)
- rect(6, 7, 5, 2)
- rect(10, 3, 2, 5)
- rect(9, 2, 2, 1)
- graph.setColor("blue")
- rect(12, 4, 1, 3)
- graph.pixel(11, 3)
- graph.pixel(10, 2)
- graph.pixel(11, 7)
- rect(6, 8, 5, 1)
- end
- graph.setColor("magenta")
- graph.print(phases[phase], 2, 13)
- if (os.day() - 9) % 36 ~= 0 then
- graph.setColor("yellow")
- graph.print(tostring(daysUntilSolar), 2, 15)
- graph.setColor("white")
- graph.print(" days until", 2 + #tostring(daysUntilSolar), 15)
- graph.print("solar eclipse", 2, 16)
- else
- graph.setColor("white")
- graph.print("Solar Eclipse is ", 4, 15)
- graph.setColor("yellow")
- graph.print("Today", 9, 16)
- end
- graph.setColor("white")
- graph.print(string.format("%02d", h) .. ":" .. string.format("%02d", m), 9, 11)
- end
- local screen = 1
- function cobalt.draw()
- if screen == 1 then
- mainScreen()
- elseif screen == 2 then
- moonScreen()
- end
- graph.setColor("white")
- graph.setBackgroundColor("white")
- graph.line(25, 0, 25, 20)
- if screen == 1 then
- graph.setColor("magenta")
- else
- graph.setColor("purple")
- end
- graph.print("S", 25, 0)
- if screen == 2 then
- graph.setColor("magenta")
- else
- graph.setColor("purple")
- end
- graph.print("M", 25, 2)
- if screen == 3 then
- graph.setColor("magenta")
- else
- graph.setColor("purple")
- end
- graph.print("C", 25, 4)
- graph.setColor("red")
- graph.print(debug, 0, 0)
- end
- function cobalt.mousepressed(x, y, m)
- --debug = x .. ", " .. y .. " : " .. m
- if m == 1 and x == 26 then
- if y >= 1 and y <= 2 then
- screen = 1
- elseif y >= 3 and y <= 4 then
- screen = 2
- elseif y >= 5 and y <= 6 then
- screen = 3
- end
- end
- if m == 1 and screen == 1 then
- if x >= 5 and x <= 23 and y == 12 then
- screen = 2
- end
- end
- end
- function cobalt.keypressed(key, keyCode)
- if key == "r" then
- os.reboot()
- end
- end
- cobalt.init()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement