Firefly

From Esolang
Jump to navigation Jump to search

Firefly is an esoteric programming language for the BBC micro:bit.

Rationale

The micro:bit is a tiny single-board computer that runs Python. It supports several input and output devices, including a speaker (version 2) and a 5x5 array of LEDs, each of which supports ten brightness levels. Firefly is a tiny esolang meant to run on the micro:bit (or the console for program development).

The language follows a "Firefly" as it flies over the 5x5 grid of LEDs. As it flies, it leaves behind it a trail of light. In this way, the Firefly can draw pictures on the 5x5 grid. The language supports music and animation via double buffering.

Firefly is featured in Chapters 14 and 15, and the appendix, of the book Strange Code: Esoteric Languages That Make Programming Fun Again (No Starch Press, 2022).

Language Description

Firefly programs are strings of single-character commands. Some affect the Firefly's movement, others music output, and others which of the two display buffers is shown and drawn to. Any string of valid command characters is a valid Firefly program, which makes the language useful for genetic programming experiments.

Commands

Instruction Effect
N Move north
S Move south
E Move east
W Move west
T Stay put (tick of the clock)
0-9 Constant intensity value
I Increment the current value
D Decrement the current value
M Move only, no change in value
R Random value 1 through 9
X Show grid A
Y Show grid B
A Draw on grid A
B Draw on grid B
C Clear active grid
V Clear grid A
Z Clear grid B
J Set note duration
G Set octave
F Play a note
P Pause for 0.1 seconds
L Loop forever
H Halt

Examples

Hi

Drawing "HI":
MNNWW7SSSMNN7EEEMNW7SSSMEEN7NNNL













Bouncing Ball

A bouncing ball (evolved screens):
YVA9MNW145NM425WSWMSII12D678I97M8MWWXZB2I6M5IN9I2 499W5989D5E775S5WS45MNEYVAD83281S355NESW89794M6M9 2926D47MNXZB57M9MEMS78I4M46MS6M95D5E5N25WSMNNWYVA MDIMS5E5S5SMW55NS749I4MD3250W9MSSEXZBW3540SESWM73 5MII75N3298525ES5SMSSYVAEWS56MW6DD4D55SIMI115WNS8 279MEMENNXZB89MDM4I972S5WEM57D5N5645WW2I4IMEEYVA2 D764I319D9112615NEI7876SMM5NEMSWWXZB1835MEN5ENW4S 97D46NIS678DDSM68MWYVA56647MN5E587795NWNMNNS5I331 334MNXZB78MNM4WN7E4MI85S94715W6N15S25SME




Radar Sweep

An animated radar sweep with "beep" (evolved screens):
YVA5383149W7EE27MEIMEWME4IEM6W74M975W932785MWWPPP PXZB37N387IM381IMIMW7495N19W645E8M9M4M188ISWMSEEP PPPYVA852MM7W4699793554MNE6791594415NSI6N42961MSS PPPPXZBMI57S49173ME83I613MN7MN6E18125IMN95EME5SMS EPPPPYVA1TJ7TF744299818E488E52I4M66I7M1462I5WW7E1 22IE1MWWPPPPXZB7E42943MSM76S6617EM55WI36M9454I57I 33M50WMNNPPPPYVA527S43M2S127778795N8E45MW57923311 776S277MNNPPPPXZB697SMW6W99857M662M377242MSI83W35
ME2125E1MNNEPPPP





Computational class

Firefly is not Turing complete.

Implementations