Last active
September 21, 2026 19:34
-
-
Save mrange/73ef7d8a161ff9951b3f077cdcc7cb38 to your computer and use it in GitHub Desktop.
TIC80 music
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pos=0 | |
| local abs = math.abs | |
| local exp2 = function(x) return 2.0 ^ x end | |
| local sin = math.sin | |
| local mod = function(a, b) return a - math.floor(a / b) * b end -- GLSL mod (always positive) | |
| local function music(t1) | |
| local a3 = 0.0 | |
| for i1 = 1, 4 do | |
| for j1 = 1, 4 do | |
| local fi = i1 * 1.0 | |
| local fj = j1 * 1.0 | |
| local r1 = math.min(t1 * fj / 32.0 + fi / 3.0, 9.0) | |
| local s1 = mod(r1, 1.0) | |
| local inner = | |
| sin(t1 * fj * fi * exp2(mod(r1 - s1, 3.0) / 6.0 + 8.0)) * 4.0 | |
| + sin(t1 * 3.0) | |
| + sin(t1 * 11.0) | |
| a3 = a3 + sin(sin(t1 / fj / 48.0) * inner) | |
| * exp2(5.0 - 13.0 * s1 - 1.0 / s1) | |
| end | |
| end | |
| if a3>1 then | |
| return 1 | |
| elseif a3<-1 then | |
| return -1 | |
| end | |
| return a3 | |
| end | |
| function TIC() | |
| cls() | |
| print("Music by PESTIS",0,0,pos/615) | |
| local tf=1/60/128 | |
| for i=0,127 do | |
| local t=(pos+i)*tf | |
| poke(0x14e24+i,127+127*music(t)) | |
| end | |
| pos=pos+128 | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment