Befunk

From Esolang
Jump to navigation Jump to search

Befunk is a Fungeoid created by User:TieSoul in 2014.

Language overview

Befunk is a non-textual derivative of Befunge-98 that takes .PNG files as program files. It is designed for steganography, and as such, it is possible to hide a Befunk program inside a picture with only slight visible differences.

Every pixel in the PNG file is considered an instruction. The instruction number of every pixel is gotten by the formula (R % 10) * 100 + (G % 10) * 10 + B % 10. This value is named the Funk value of the pixel.

Concurrency is not implemented in the original interpreter, but would theoretically work the same as in Befunge. The instruction 700 is recommended for this purpose if an interpreter with concurrency is ever made.

Overview of instructions:

Funk val Befunge equivalent Description
000 - 016 0 - f Pushes number represented by the Funk val to the stack.
050 > Delta right
051 ^ Delta up
052 v Delta down
053 < Delta left
054 _ Horizontal IF: pop a value; move right if value=0, left otherwise
055 | Vertical IF: pop a value; move down if value=0, up otherwise
056 [ Turns delta 90 degrees left.
057 ] Turns delta 90 degrees right.
058 x pop two values a and b. Set delta to (b,a).
059 w Pop two values a and b; acts like instruction 056 if a %lt; b, acts like instruction 057 if a %rt; b, and does nothing if a == b
060 ? Delta is set to a random one of left, right, up or down.
100 , Pop a value; output the ASCII character corresponding to the value % 256.
101 . Pop a value; output the value.
102 & Gets an int from input.
103 ~ Gets a char from input.
150 + Addition: Pop a and b, then push a+b
151 - Subtraction: Pop a and b, then push b-a
152 * Multiplication: Pop a and b, then push a*b
153 / Integer division: Pop a and b, then push b/a, rounded down. if a is zero, push zero.
154 % Modulo: Pop a and b, then push the remainder of the integer division of b/a. If a is zero, push zero.
175 : Duplicate top stack value
176 \ Swap top two stack values
200 # Jump over next command.
201 j Pop value a; jump over next a commands.
202 k Pop value a; execute the next command a times.
256 " (but not really) Toggle Pushmode (push funk value % 256 all the way up to the next 256)
300 g A "get" call (a way to retrieve data in storage). Pop y and x, then push funk value at that position in the program
301 p A "put" call (a way to store a value for later use). Pop y, x and v, then change the cell at the position (x,y) in the program to the funk value v.
302 ' executes command 300 on the next instruction, then skips it.
303 s executes command 301 on the next instruction.
350 ! NOT: Pop a; push NOT a.
351 ` Greater than: Pop a and b, then push 1 if b>a, otherwise zero.
400 { Pops a value a. Then pushes an empty stack onto the stack stack. Then it transfers a values from the old stack to the new stack,retaining their order. If a < 0, |a| zeroes get pushed onto the old stack. If a == 0, nothing gets transferred. Then, it pushes the storage offset to the old stack in order x, y, and then sets the storage offset to the next instruction.
401 } Pops a value a from the top stack, then pops two values b and c from the second stack. It sets the storage offset to [c,b], then transfers a values from the top stack to the second stack, retaining their order. If a < 0, |a| values get popped off the second stack. If a == 0, nothing gets transferred. Then it pops the top stack off the stack stack.
402 u Pops a value a, then transfers a values from the second stack to the top stack, reversing their order. If a < 0, |a| values get transferred from the top stack to the second stack, reversing their order. If a == 0, nothing happens.
500 n Clears the stack.
501 $ Pops a value.
554 z Does nothing, and takes up a tick.
555 (space) Does nothing, and does not take up a tick.
998 q Pops value a; quits program with exit value a.
999 @ Quits program with exit value 0.

Computational class

This language can do anything Befunge-98 can do, and thus is Turing-complete.

Examples

Hello world

This is a LifeViewer code. Please compile it into Hexdump or a picture if possible. Not sure if working.

Click here for a LifeViewer display (dead link)

[code]x = 0, y = 0, rule = LifeColorful
BQMDLROWFCO2LEHQJPNDIX!
[[ COLOR 0 255 255 255 ]]
[[ COLOR 2 0 0 0 ]]
[[ COLOR 3 0 144 144 ]]
[[ COLOR 4 171 0 0 ]]
[[ COLOR 5 171 0 251 ]]
[[ COLOR 6 0 243 192 ]]
[[ COLOR 8 0 127 192 ]]
[[ COLOR 9 0 255 144 ]]
[[ COLOR 10 0 255 0 ]]
[[ COLOR 12 171 0 128 ]]
[[ COLOR 13 0 243 243 ]]
[[ COLOR 14 192 0 0 ]]
[[ COLOR 15 171 171 171 ]]
[[ COLOR 16 171 127 255 ]]
[[ COLOR 17 192 255 216 ]]
[[ COLOR 18 171 171 144 ]]
[[ COLOR 23 171 171 99 ]]
[[ COLOR 24 249 99 249 ]][/code]

Note: The "D" (declared with funk value 100) does double duty in the above code.

Project Euler

Pictured below is Project Euler's Problem 1 in Befunk, hidden in an image which depicts the solution of said problem.

Befunk-euler1.png

External resources