I bloody love @llamasoft_ox on a train. It’s brill…

I bloody love @llamasoft_ox on a train. It’s brilliant writing.

I love the way Dettol louches with water. Like goo…

I love the way Dettol louches with water. Like good absinthe.

Angort joy

Yes, it’s my own language, and I use it largely out of bloodymindedness. But the more I use it, the more I find it’s actually bloody good. Here’s an example.

I’m working with a homemade dataglove (and perhaps more on that later) which requires a bit of postprocessing on the input. For example, it’s useful to smooth the accelerometer values, and do edge detection on the “buttons” (when the fingertips touch the thumb).

In Angort, we can write a general purpose “smoother” or low-pass filter which does

x_t = (1-k)i + kx_{t-1}

(i.e. the output is k times the last output plus 1-k times the input) by writing a function to make smoothing functions:

:mksmoother |factor:prev| 
    none!prev
    (|val:|
        ?prev isnone if ?val!prev then
        ?val 1.0 ?factor -  * ?prev ?factor * +
        dup !prev
    )
;

It might look a bit hairy, but it’s pretty straightforward once you’re used to the syntax.
Whenever we need to smooth an input, Angort allows us to create smoothers inline at compile time using the << >> syntax:

dataglove$x <<0.9 mksmoother>>@ !SX
dataglove$y <<0.9 mksmoother>>@ !SY
dataglove$z <<0.9 mksmoother>>@ !SZ

Each of these lines reads the accelerometer value for an axis, runs it through a smoother with a smoothing constant of 0.9, and stores it in another variable. Each smoother has its own state, through the joy of closures.

Similarly with edge detectors:

:mkposedgedetect |:prev|
    0!prev
    (
        |i:|
        ?i ?prev not and if 1 else 0 then
        ?i !prev
    )
;

:getbuttondown
    # use positive edge detectors to spot the button down.

    cases
        dataglove$ismiddledown <<mkposedgedetect>>@
          if `middle case
        dataglove$isindexdown <<mkposedgedetect>>@
          if `index case
        dataglove$isringdown <<mkposedgedetect>>@
          if `ring case
        dataglove$islittledown <<mkposedgedetect>>@
          if `little case
        none otherwise
;

Here we use the case syntax, which is more like if..elseif..elseif..else in other languages.

I might be wrong, but it strikes me that using and creating these anonymous functions inline in this way would be quite tricky in most other languages.

Jeff Minter being threatened by Atari lawyers for…

Jeff Minter being threatened by Atari lawyers for making games that look like Jeff Minter games. FFS.

Please help support my wife’s play about Alan Turi…

Please help support my wife’s play about Alan Turing – MUCH better than The Imitation Game! kickstarter.com/projects/scrip…

I just saw Ezio Auditore walking along the prom.

I just saw Ezio Auditore walking along the prom.

I want a Bernard Bresslaw sat nav.

I want a Bernard Bresslaw sat nav.

Johnny Mnemonic. Weird putting this through an inv…

Johnny Mnemonic. Weird putting this through an inverse 80’s-cyberpunk filter. Anonymous/Wikileaks = LoTeks?

W Ross Ashby: “A common, though despised, property…

W Ross Ashby: “A common, though despised, property of every machine is that it may ‘break’.” Testify, brother.

#Scorpion – best comedy on telly, or it would be i…

#Scorpion – best comedy on telly, or it would be if not for the autism clichés.

Copyright © Found
Jim Finnis' personal blog

Built on Notes Blog Core
Powered by WordPress