ifunge

From Esolang
Jump to navigation Jump to search

ifunge /ˈaɪfʌndʒ/ (name always lowercase) is an image version of Befunge, created by User:None1

Syntax

ifunge programs are grayscale images, the grayscaleof each pixel represents an ASCII character in a Befunge program (e.g., A pure black pixel stands for a null character). When running, ifunge programs transpile into Befunge.

Example Program

Hello World

Enlarged view

ifunge hello world

Actual size

ifunge hello world

Cat Program

Enlarged view

ifunge cat

Actual size

ifunge cat

99 bottles of beer

Enlarged view

ifunge 99 bottles of beer

Actual size

ifunge 99 bottles of beer

Interpreters

Here is a translator from ifunge to Befunge, in Python:

# ifunge translator to Befunge
# usage: python ifunge.py <image file name>
from PIL import Image
import numpy as np
import sys
img=Image.open(sys.argv[1])
a=np.array(img)
for i in a:
    for j in i:
        if not hasattr(j,'__iter__'):
            j=[j]
        print(chr(max(j)),end='')
    print()

And an encoder from Befunge to ifunge:

from PIL import Image
import numpy as np
import sys
k=sys.stdin.read().split('\n')
l=[]
maxlen=0
for i in k:
    maxlen=max(maxlen,len(i))
for i in k:
    y=[]
    for j in range(0,maxlen):
        try:
            y.append(ord(i[j]))
        except:
            y.append(32)
    l.append(y)
Image.fromarray(np.array(l),mode='L').save(sys.argv[1])

They require pillow and numpy packages.