Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- from https://oc.cil.li/index.php?/topic/267-palette-based-hologram-animations/
- --[[holo-wave.lua]]--
- local keyboard = require("keyboard")
- local component = require("component")
- local hologram = component.hologram
- hologram.clear()
- -- because tau is better than Pi
- local tau = math.pi * 2
- -- magic numbers
- local scale = 10 -- the size of the hologram
- local offset = 20 -- the hologram offset from zero which is the zero axis of the sine wave
- -- our colours
- local dark = 0 -- palette value for "off"
- local dim = 0x661133 -- palette value for "nearly off" - change this to 0 for a less subtle animation
- local light = 0xff0000 -- palette value for "on"
- -- draw our sine waves
- -- no need to do it 3 times, but this is an offset to the sin function/voxel position, which makes the image "thicker"
- for n = 1,3 do
- os.sleep(0.01)
- for x = 1,48 do
- for y = 1,48 do
- -- you do the math[s] - the principle is simple sin(x) varies from 0 to 1,
- -- but we want to scale that up, hence the scale
- local z = math.sin( ( y - x + n) / tau ) * scale + offset
- -- this might look tricky, but tis just getting the next colour in a sequence of
- -- 1,2,3,1,2,3,1,2,3... etc... in a way which matches the angle of the wave
- -- play with the formula [leaving the %3 + 1 bit] to get funkier ripples
- local col = (( y - x + n) % 3) + 1
- hologram.set( x, z, y, col)
- if keyboard.isKeyDown(keyboard.keys.q) then -- quicktime event "press q to die" ;)
- break
- end
- end
- end
- end
- -- do the animation, i have set this to just 100 for a demo...
- -- loop if forever if you want, but beware, there is no yielding for the purposes of speed/smoothness
- for n = 1, 100 do
- -- the % [modulo] bits here are just to get a sequence as 1,2,3 : 2,3,1 : 3,1,2 : 1,2,3 etc..
- -- for each of the 3 colours [including dark/off]
- hologram.setPaletteColor(((n-2) % 3) + 1,dark)
- hologram.setPaletteColor(((n-1) % 3) + 1,dim)
- hologram.setPaletteColor((n % 3) + 1,light)
- end
Advertisement
Add Comment
Please, Sign In to add comment