Last active
May 22, 2016 14:53
-
-
Save bowbahdoe/5bbdf95874bfc30f0b9fae1ab42cb7cb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # -*- coding: utf-8 -*- | |
| from __future__ import print_function | |
| import sys | |
| import os | |
| filename = sys.argv[1] | |
| output_name = 'emoji' | |
| c_code =''' | |
| #define cell_size 1000 | |
| #include <stdlib.h> | |
| #include <stdio.h> | |
| #include <time.h> | |
| int main(){ | |
| char data[cell_size][cell_size] = {0}; | |
| srand(time(NULL)); | |
| int x = 0; | |
| int y = 0; | |
| %s | |
| return 0; | |
| } | |
| ''' | |
| #small superset of bf also supported | |
| code_equivalance = { | |
| '+': '(data[x][y])++;\n', | |
| '-': '(data[x][y])--;\n', | |
| '>': 'x++;\n', | |
| '<': 'x--;\n', | |
| ',': 'data[x][y] = getchar();\n', | |
| '.': 'putchar(data[x][y]);\n', | |
| '*': 'printf(\"%d\", (int) data[x][y] );\n', | |
| '!': 'printf("\\n");\n', | |
| '[': 'while(data[x][y]){\n', | |
| ']': '}\n', | |
| #Happy emojis add one to the value at the location, | |
| #sad emojis subtract | |
| '๐': '(data[x][y])++;\n', | |
| 'โน': '(data[x][y])--;\n', | |
| #right and left pointing move right and left | |
| '๐': 'x++;\n', | |
| '๐': 'x--;\n', | |
| #middle finger moves up, | |
| '๐': 'y++;\n', | |
| #pointing finger up moves up | |
| 'โ': 'y++;\n', | |
| '๐': 'y++;\n', | |
| '๐': 'y++;\n', | |
| #pointing down goes down | |
| '๐': 'y--;\n', | |
| '๐': 'y--;\n', | |
| #upleft arrow goes upleft | |
| 'โ': 'y++;x--;\n' | |
| #upright arrow goes upright | |
| 'โ': 'y++;x++;\n' | |
| #downright goes downright | |
| 'โ': 'y--;x++;\n' | |
| #downleft goes downleft | |
| 'โ': 'y--;x--;\n' | |
| #doubleup arrow goes two up | |
| 'โซ': 'y+=2;\n' | |
| #doubledown arrow goes down two | |
| 'โฌ': 'y-=2;\n' | |
| #sleepy face waits for input then stores it in the cell | |
| '๐ช': 'data[x][y] = getchar();\n', | |
| #kissy face prints out the value as ASCII | |
| '๐': 'putchar(data[x][y]);\n', | |
| #sun and full moon w/ face start and close loops | |
| #where it loops if the value at the end is not zero | |
| '๐': 'while(data[x][y]){\n', | |
| 'โ': 'while(data[x][y]){\n', | |
| '๐': '}', | |
| #winky face prints a newline | |
| '๐': 'printf("\\n");\n', | |
| #open mouth suprised face waits for one char of input | |
| '๐ฎ': 'data[x][y] = getchar();\n', | |
| #poop emoji dumps the entire stack, not pretty, dont use | |
| '๐ฉ': 'for (int i = 0; i<cell_size;i++){\n \ | |
| for(int e = 0; e<cell_size;e++){\n \ | |
| printf("%d",(int) data[i][e]);\ | |
| }\ | |
| printf("\\n");\ | |
| }', | |
| #Die emoji puts a random value between 1 and 6 in the cell | |
| '๐ฒ': 'data[x][y] = (char)(rand() % 6) + 1;', | |
| #nerd face prints out the value in the cell as a number | |
| #because nerds and numbers amiright | |
| '๐ค': 'printf(\"%d\", (int) data[x][y] );\n' | |
| } | |
| def loadbf(filename): | |
| data = '' | |
| with open(filename) as bffile: | |
| for line in bffile: | |
| data += line | |
| data = [char for char in data if char in code_equivalance.keys()] | |
| code='' | |
| for i in data: | |
| code+=i | |
| return code | |
| symbols = loadbf(filename) | |
| code = '' | |
| #print(symbols) | |
| for symbol in symbols: | |
| code += code_equivalance[symbol] | |
| c_code = c_code % code | |
| print(c_code) | |
| with open("c_code.c", "w") as code_file: | |
| code_file.write(c_code) | |
| os.system("gcc -std=c99 c_code.c -o bf") | |
| os.system("rm c_code.c") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ๐๐๐๐๐๐๐๐๐๐ | |
| ๐๐๐๐๐๐๐๐๐๐ | |
| ๐๐๐๐๐๐๐๐๐๐ | |
| ๐๐๐๐๐๐๐๐๐๐ | |
| ๐๐๐๐๐๐๐๐๐๐ | |
| ๐๐๐๐๐๐๐๐๐๐ | |
| ๐๐๐๐๐๐๐๐๐๐ | |
| ๐๐๐๐๐๐๐๐๐๐ | |
| ๐๐๐๐๐๐๐๐๐๐ | |
| ๐๐๐๐๐๐๐๐๐๐ Stores h in the first cell | |
| ๐๐๐๐ | |
| ๐ | |
| โนโนโน e | |
| ๐ | |
| ๐๐๐๐๐๐๐ l | |
| ๐๐ | |
| ๐๐๐ o | |
| ๐ ๐ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment