ÎÌÌÌ̈ˆˆ¬ªªª¬ˆˆˆ¬ÌÌ̬ÌÀ̬ÌÀ̬ÌÀÌÌÌìÌÀÀî̬ÀÌÀ¬ÀÀÀ¬ÀÀÀ¬ÀÀÎÌÌÌ̈ˆˆ¬ªªª¬ˆˆˆ¬ÌÌ̬ÌÌ̬ÌÀ̬ÌÀÌÌÌìÌÀÀî̬ÀÌ̬ÀÀÀ¬ÀÀÀ¬ÀÀ¬ÌÌ̬ªªª¬ª¬ª¬ªÊ̬ªªªŒˆˆˆÌÀÌÎÌÌÎ̬̪ªÀ쬪ÀÀÀÌîÀìîÌÌîî¬ÌÌ̬ªªª¬ª¬ª¬ªÊ̬ªªªŒˆˆˆÌÀÌÎÌÌÎ̬̪ªÀ쬪ÀÀÀÌîÀìîÌÌîî >À?ñÿññÿÿADDDDDDD3333333"""""""ADDDDDDDADDD3313!"!"ADDDDD131"!"ADDA113!""DADA33!!DADAA33!!DA13!!DAA1"AAD11""AAD1!A33!!DDA1!AD1#BA3!111AA!1D"1A3!1!11AA!D!1313D!11A"A"!11!1AA!!13!1A3D!11A"A"!!111AA!!!13!1AD!1A"1A"!3!111AA!!D!13!13D!11A"A"!!11!1AD!11BA#!!D133!!D31!1"AA1!1"DA1"!!DA133!!D13!3!!D33!3!!AD33!3!"ADAD33!13!""DA113!""""ADAD133""!""""""""DDDDDDDD133333333""""æ-- title: Palette modification test -- author: Sava -- desc: Simple rainbows made with palette modifications -- version: 0.1 -- script: lua w=240 h=136 t=0 last = {} function BOOT() setCol(2, 255, 0, 0) setCol(3, 0, 255, 0) setCol(4, 0, 0, 255) end press = true func = 0 maxFunc = 3 function TIC() if btnp(0) then press = false func = (func+1+maxFunc)%maxFunc end if btnp(1) then press = false func = (func-1+maxFunc)%maxFunc end local r1, g1, b1 = getRanbow(time()/500.0) last[#last+1]={r1, g1, b1} setCol(1, r1, g1, b1) cls(1) if press then print("press up/down to switch the function") else print(func+1) end for i=1, math.min(w, #last) do pix(i, h/2-last[i][1]/5, 2) pix(i, h/2-last[i][2]/5, 3) pix(i, h/2-last[i][3]/5, 4) end if #last > w then table.move(last, 2, #last+1, 1) end t=t+1 end function getRanbow(t) if func == 0 then return rainbow1(t) elseif func == 1 then return rainbow2(t) elseif func == 2 then return rainbow3(t) end end function rainbow1(t) local r = math.cos(t)*127+127 local g = math.cos(t+(math.pi*2/3))*127+127 local b = math.cos(t+(math.pi*4/3))*127+127 return r, g, b end function rainbow2(t) local gt = (t*50)%256 if gt < 85 then return (85-gt)*3, gt*3, 0 elseif gt < 170 then return 0, (170-gt)*3, (gt-85)*3 else return (gt-170)*3, 0, (255-gt)*3 end end function rainbow3(t) local gt = (t%6)+1 local palette = { {255, 0, 0}, {255, 255, 0}, {0, 255, 0}, {0, 255, 255}, {0, 0, 255}, {255, 0, 255}, {255, 0, 0} } local cur = palette[math.floor(gt)] local next = palette[math.floor(gt)+1] local curOff = t%1 local r = lerpInOutCubic(curOff, cur[1], next[1], 1.0) local g = lerpInOutCubic(curOff, cur[2], next[2], 1.0) local b = lerpInOutCubic(curOff, cur[3], next[3], 1.0) return r, g, b end function lerpInOutCubic(t, startValue, endValue, duration) if t <= 0 then return startValue end if t >= duration then return endValue end t = t / duration * 2 if t < 1 then return (endValue - startValue) / 2 * t * t * t + startValue else t = t - 2 return (endValue - startValue) / 2 * (t * t * t + 2) + startValue end end function setCol(idx, r, g, b) poke(0x3FC0+idx*3, r, 8) poke(0x3FC0+idx*3+1, g, 8) poke(0x3FC0+idx*3+2, b, 8) end