Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
ingie

Palette based hologram animations

Recommended Posts

If you've never done this before, you'll love it... i hope :)

 

 

Back in the 80s, at school, we had the wonderful Acorn [who went on to become ARM] "BBC" Machines... the BBC Model A and B...

later superseded by the BBC Master series machines [of which I have two here in my flat, whoo get me and my retro stuff ;)

amazing machines for their time, a gazillion and one external output ports for connecting analogue devices and parallel processors n stuff.

anyway, one of the wonderful things about the BBC Basic was the often missed VDU command, which could be used in certain graphical modes to swap one palette colour for another... i remember sitting in a school induction day for next years pupils, making spheres rotate and stuff, just by doing palette swapping, whilst the visiting parents went "ooooh, look jimmy, you could do this..." 
 

So, ingie? i hear you ask...

 

well, the same command exists, in effect, within the hologram api on OC... hologram.setPaletteColour*cough ok*Color( paletteindex, hexcolourvalue )

what you might not realise that this enables is simple animation techniques which don't require re-drawing the hologram.

 

hows that then?

 

quite simple...

  • we have 3 available colours, not counting 0/ black, which we can't change the palette of.
  • we draw each of our "frames" in one of those three hologram colours 1,2 and 3
  • we then cycle through each colour, changing all but the current one's palette entry to 0x000000, and the current one to whatever we want the animation colour to be...

 

an example would be nice wouldn't it, ingie... yes, yes it would...

 

here's a short piece to give you an idea of what's capable with this... it draws a series of sine waves, and then cycles the colours to create a moving "wave" across the sine graph. 

 

i'll spoiler it, rather than attach it, as it's small, and an attachment means you have to download and open something :)
i hope it makes sense, if not... feel free to ask.

 

peace and stuff, ingie. 

 

--[[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 
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.