Exemplo n.º 1
0
def test_run(main=False):

    fout = StringIO()
    bfck = BrainFck(fout=fout,
                    linemode=True,
                    multiline=True,
                    comments=True,
                    breakline=True)

    bfck.run(test_program)

    if main:
        print(fout.getvalue())
        print('len fout:', len(fout.getvalue()))
        print('len output:', len(test_output))

    assert fout.getvalue() == test_output
Exemplo n.º 2
0
from PIL import Image
from pybrainfuck import BrainFck

# Read image and get pixel data as list
pixels = list(Image.open('brainfun.png').getdata())

# Extract just get the blocks. Fun fact: PIL's resize with PIL.Image.NEAREST
# for nearest neighbor messes with the values, but mtPaint does it correctly.
pixels = [pixels[r*512 + c] \
  for r in range(0, 512, 16) \
  for c in range(0, 512, 16)]

# Sort the pixels by RGB value
pixels.sort(key=lambda p: (p[0] << 8) + (p[1] << 4) + p[2])

# Run the alpha values as Brainfuck
BrainFck().run(u"".join([chr(p[3]) for p in pixels]))
Exemplo n.º 3
0
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
###############################################################################
from __future__ import (absolute_import, division, print_function,
                        unicode_literals)

import sys

from pybrainfuck import BrainFck

if __name__ == '__main__':

    bfck = BrainFck()

    for arg in sys.argv[1:]:
        print('-' * 50)
        print('Running:', arg)
        print('-' * 50)
        bfck.runfiles(arg)
        print()