Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- term.setGraphicsMode(2)
- term.setFrozen(true)
- local filename = "qqwomk.raw"
- if not fs.exists(filename) then
- local success = shell.run("wget", "https://files.catbox.moe/qqwomk.raw", filename)
- if not success then
- filename = nil
- end
- end
- local speaker = peripheral.find("speaker")
- local audioThread = nil
- if speaker and filename then
- audioThread = coroutine.create(function()
- local file = fs.open(filename, "rb")
- if not file then coroutine.yield() return end
- local samples = {}
- while true do
- local byte = file.read()
- if not byte then break end
- samples[#samples + 1] = byte - 128
- end
- file.close()
- local inputRate = 64000
- local outputRate = 48000
- local ratio = inputRate / outputRate
- local resampled = {}
- for i = 1, math.floor(#samples / ratio) do
- local src = (i - 1) * ratio + 1
- local idx = math.floor(src)
- local frac = src - idx
- local s1 = samples[idx] or 0
- local s2 = samples[idx + 1] or s1
- resampled[i] = s1 + (s2 - s1) * frac
- end
- local volume = 2
- local chunkSize = 64 * 1024
- local totalSamples = #resampled
- local position = 1
- while true do
- local chunk = {}
- for i = 1, chunkSize do
- local idx = position + i - 1
- if idx > totalSamples then
- position = 1
- break
- end
- local sample = math.floor(resampled[idx] * volume + 0.5)
- sample = math.max(-128, math.min(127, sample))
- chunk[i] = sample
- end
- if #chunk > 0 then
- while not speaker.playAudio(chunk) do
- os.pullEvent("speaker_audio_empty")
- end
- end
- position = position + #chunk
- if position > totalSamples then
- position = 1
- end
- end
- end)
- coroutine.resume(audioThread)
- end
- local sin = math.sin
- local cos = math.cos
- local w, h = term.getSize(2)
- local barCount = math.min(200, h)
- local stripWidth = 12
- local halfStrip = stripWidth / 2
- local centerX = math.floor(w / 2)
- local t = 0
- local copperSize = 64
- for i = 0, copperSize - 1 do
- local hue = (i * 0.1 + t * 0.5) % 6.283185
- local r = (sin(hue) * 0.5 + 0.5) ^ 0.7
- local g = (sin(hue + 2.0944) * 0.5 + 0.5) ^ 0.7
- local b = (sin(hue + 4.1888) * 0.5 + 0.5) ^ 0.7
- term.setPaletteColor(i, r, g, b)
- end
- local redMetal = {180, 181, 182, 183}
- term.setPaletteColor(180, 0.55, 0.08, 0.08)
- term.setPaletteColor(181, 0.75, 0.12, 0.12)
- term.setPaletteColor(182, 0.95, 0.22, 0.22)
- term.setPaletteColor(183, 0.65, 0.10, 0.10)
- local goldMetal = {190, 191, 192, 193}
- term.setPaletteColor(190, 0.55, 0.45, 0.08)
- term.setPaletteColor(191, 0.75, 0.65, 0.12)
- term.setPaletteColor(192, 0.95, 0.85, 0.22)
- term.setPaletteColor(193, 0.65, 0.55, 0.10)
- while true do
- term.clear()
- for y = 0, h - 1 do
- local c = math.floor(((y * 0.8 + t * 15) % copperSize + copperSize) % copperSize)
- term.drawPixels(0, y, c, w, 1)
- end
- for i = barCount, 1, -1 do
- local height = i
- local y = barCount - i
- local x = math.floor(
- centerX
- + centerX
- * sin(t + i / 20)
- * sin(t + i / 48)
- )
- for band = 0, halfStrip - 1 do
- local xx = x + band
- if xx >= 0 and xx < w then
- local col = redMetal[(band % #redMetal) + 1]
- term.drawPixels(xx, y, col, 1, height)
- end
- end
- for band = 0, halfStrip - 1 do
- local xx = x + halfStrip + band
- if xx >= 0 and xx < w then
- local col = goldMetal[(band % #goldMetal) + 1]
- term.drawPixels(xx, y, col, 1, height)
- end
- end
- end
- if audioThread and coroutine.status(audioThread) ~= "dead" then
- coroutine.resume(audioThread)
- end
- t = t + 0.05
- term.setFrozen(false)
- sleep(0.04)
- term.setFrozen(true)
- end
Add Comment
Please, Sign In to add comment