Prequel
primitive recursive driven programming


Blinkp

(This example requires web workers.)

Blinkp is an unofficial Prequel adaptation of Pimoroni's Blinkt! — a Raspberry Pi add-on with 8 RGB LEDs.
Create simple animations while honing your Prequel skills.
Learn about this adaptation in the author's blog.

Shuffle Clear

Run Pause Stop

0
0
0
← calls
← instructions
← memory (max use: 0)


Prequel program

Edit Save Debug

Module: EXIT

BLINKP.SHOW_AND_EXIT()

Input:

BLINKP.NUM_PIXELS
  Total number of pixels.
  -> 8
  This value is constant.
BLINKP.ELAPSED_TIME
  Total number of milliseconds elapsed since the beginning of program execution.
BLINKP.COLOR_UNIT
  Represents one unit in the Blinkp color space conversion utilities.
  -> 10000
  This value is constant.
  Can be used to convert an RGB value
    (in range {0, ..., 255})
    to and from other color spaces
    when using procedures
       BLINKP.RGB_TO_YIQ,
       BLINKP.YIQ_TO_RGB,
       BLINKP.RGB_TO_HLS,
       BLINKP.HLS_TO_RGB,
       BLINKP.RGB_TO_HSV,
    or BLINKP.HSV_TO_RGB.
MODULE.CALL.ARGS
  Holds the list of arguments passed with MODULE.CALL.
  -> [arg1, ..., argN]

Procedures:

BLINKP.GET_PIXEL(&r, &g, &b, &brightness?, index)
  Get RGB values and brightness of the pixel at index.
  The brightness return variable is optional.
  -> r: integer between 0 and 255
  -> g: integer between 0 and 255
  -> b: integer between 0 and 255
  -> brightness: integer between 0 and 10
  -> index: integer between 0 and BLINKP.NUM_PIXELS-1
  Alternative syntax: r, g, b, brightness? := BLINKP.GET_PIXEL(index)
BLINKP.SET_PIXEL(index, r, g, b, brightness?)
  Set pixel at index with RGB values r g b and the specified brightness.
  The brightness argument is optional; if not used, it keeps the previous value.
  -> index: integer between 0 and BLINKP.NUM_PIXELS-1
  -> r: integer between 0 and 255
  -> g: integer between 0 and 255
  -> b: integer between 0 and 255
  -> brightness: integer between 0 and 10
  Changes take effect after the next call to
    BLINKP.SHOW_AND_WAIT or BLINKP.SHOW_AND_EXIT.
BLINKP.CLEAR()
  Shorthand for BLINKP.SET_ALL(0, 0, 0).
BLINKP.SET_ALL(r, g, b, brightness?)
  Equivalent to calling BLINKP.SET_PIXEL for all pixels:
    BLINKP.SET_PIXEL(0, r, g, b, brightness?)
    BLINKP.SET_PIXEL(1, r, g, b, brightness?)
    ...
    BLINKP.SET_PIXEL(BLINKP.NUM_PIXELS-1, r, g, b, brightness?)
BLINKP.SET_BRIGHTNESS(brightness)
  Set the brightness value of all pixels to brightness.
  -> brightness: integer between 0 and 10
  Changes take effect after the next call to
    BLINKP.SHOW_AND_WAIT or BLINKP.SHOW_AND_EXIT.
BLINKP.SHOW_AND_WAIT(milliseconds)
  Commit changes to the display and wait the specified milliseconds
    before continuing execution by restarting the program counter.
BLINKP.SHOW_AND_EXIT()
  Commit changes to the display and halt the program.
BLINKP.RGB_TO_YIQ(&y, &i, &q, r, g, b)
BLINKP.YIQ_TO_RGB(&r, &g, &b, y, i, q)
BLINKP.RGB_TO_HLS(&h, &l, &s, r, g, b)
BLINKP.HLS_TO_RGB(&r, &g, &b, h, l, s)
BLINKP.RGB_TO_HSV(&h, &s, &v, r, g, b)
BLINKP.HSV_TO_RGB(&r, &g, &b, h, s, v)
  Convert values between different color spaces
    using BLINKP.COLOR_UNIT as the unit value.
  Alternative syntax: x, y, z := BLINKP.ABC_TO_XYZ(a, b, c)
MODULE.CALL(&retvar1, ..., &retvarM, @modname, arg1, ..., argN)
  Start executing module modname, copying N arguments and expecting M return values.
  -> retvar: name of variable to hold the corresponding return value retval
  -> modname: name of module to start executing
  -> arg: value to be copied to the list MODULE.CALL.ARGS
  Alternative syntax: retvar1, ..., retvarM := MODULE.CALL(@modname, arg1, ..., argN)
  Note that recursive module calls are not allowed.
MODULE.RETURN(retval1, ..., retvalM)
  Return M values from the current module.
  Resume execution at the next instruction of the corresponding MODULE.CALL.
  -> retval: value to be copied to the corresponding variable retvar

Additional examples can be found on GitHub.