|
| 1 | +# change python syntax and define functions |
| 2 | +import tokenize |
| 3 | +from io import BytesIO |
| 4 | +import tkinter |
| 5 | +from tkinter import * |
| 6 | +import turtle |
| 7 | +import matplotlib.pyplot as plt |
| 8 | +import sys |
| 9 | +from statistics import * |
| 10 | +fro flask import * |
| 11 | + |
| 12 | +tur = turtle |
| 13 | + |
| 14 | +window = tkinter |
| 15 | + |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | +def process_code(file): |
| 20 | + keys = { |
| 21 | + |
| 22 | + "log":"print", |
| 23 | + "ask": "input", |
| 24 | + "convertInt":"int", |
| 25 | + "convertStr":"str", |
| 26 | + "else if":"elif", |
| 27 | + "//":"#", |
| 28 | + "get":"import", |
| 29 | + "size":"len", |
| 30 | + "f":"format", |
| 31 | + "x=":"!=", |
| 32 | + "delete":"del", |
| 33 | + "with_name":"as", |
| 34 | + "function":"def", |
| 35 | + "toLowerCase":"lower", |
| 36 | + "toUpperCase":"upper", |
| 37 | + "firstLetterUpper":"title", |
| 38 | + "skip":"pass" |
| 39 | + |
| 40 | + |
| 41 | + |
| 42 | + |
| 43 | + |
| 44 | + } |
| 45 | + |
| 46 | + def __init__(): |
| 47 | + pass |
| 48 | + def add(num1, num2): |
| 49 | + x = num1+num2 |
| 50 | + return x |
| 51 | + def window(title): |
| 52 | + window.Tk() |
| 53 | + window.title(title) |
| 54 | + window.mainloop() |
| 55 | + return |
| 56 | + |
| 57 | + def subtract(num1, num2): |
| 58 | + yx = num1-num2 |
| 59 | + return yx |
| 60 | + def multiply(num1, num2): |
| 61 | + xy = num1*num2 |
| 62 | + return xy |
| 63 | + def divide(num1, num2): |
| 64 | + xyx = num1/num2 |
| 65 | + return xyx |
| 66 | + def artboard(color): |
| 67 | + tur.turtle = turtle.Turtle() |
| 68 | + screen = turtle.Screen() |
| 69 | + screen.title("VisualScript Art Window") |
| 70 | + tur.turtle.color(color) |
| 71 | + return |
| 72 | + def artColor(color): |
| 73 | + tur.turtle.color(color) |
| 74 | + return |
| 75 | + def artLeft(amount): |
| 76 | + tur.turtle.left(amount) |
| 77 | + return |
| 78 | + def artRight(amount): |
| 79 | + tur.turtle.right(amount) |
| 80 | + return |
| 81 | + def artForward(amount): |
| 82 | + tur.turtle.forward(amount) |
| 83 | + return |
| 84 | + def artBackward(amount): |
| 85 | + tur.turtle.backward(amount) |
| 86 | + return |
| 87 | + def artClose(): |
| 88 | + tur.turtle.exitonclick() |
| 89 | + return |
| 90 | + def artSpeed(speed): |
| 91 | + tur.turtle.speed(speed) |
| 92 | + return |
| 93 | + def artColor(color): |
| 94 | + tur.turtle.color(color) |
| 95 | + return |
| 96 | + def artKey(function, key): |
| 97 | + tur.turtle.onkey(function, key) |
| 98 | + tur.turtle.listen() |
| 99 | + return |
| 100 | + def artStatic(feature): |
| 101 | + if feature == "stamp": |
| 102 | + tur.turtle.stamp() |
| 103 | + elif feature == "dot": |
| 104 | + tur.turtle.dot() |
| 105 | + def ForeverRun(): |
| 106 | + while True: |
| 107 | + pass |
| 108 | + def chartLine(datasetx, datasety, ytitle, xtitle): |
| 109 | + plt.plot(datasetx, datasety) |
| 110 | + plt.ylabel(ytitle) |
| 111 | + plt.xlabel(xtitle) |
| 112 | + plt.show() |
| 113 | + def chartDot(datasetx, datasety, ytitle, xtitle): |
| 114 | + plt.scatter(datasetx, datasety) |
| 115 | + plt.xlabel(xtitle) |
| 116 | + plt.ylabel(ytitle) |
| 117 | + def chartScatter(datasetx, datasety, xtitle, ytitle): |
| 118 | + timesx = len(datasetx) |
| 119 | + for i in range(timesx): |
| 120 | + plt.scatter(datasetx[i], datasety[i]) |
| 121 | + plt.xlabel(xtitle) |
| 122 | + plt.ylabel(ytitle) |
| 123 | + plt.show |
| 124 | + def chartTheme(theme): |
| 125 | + plt.style(theme) |
| 126 | + return |
| 127 | + def windowTitle(title): |
| 128 | + window.title(title) |
| 129 | + return |
| 130 | + def ArtBoardTitle(name): |
| 131 | + screen = turtle.Screen() |
| 132 | + screen.title(name) |
| 133 | + return |
| 134 | + |
| 135 | + def ChartShow(): |
| 136 | + plt.show() |
| 137 | + return |
| 138 | + def logf(value, formatedvalue): |
| 139 | + print(value+"{}".format(formatedvalue)) |
| 140 | + return |
| 141 | + def returnMedian(list, chart): |
| 142 | + sortedlist = sorted(list) |
| 143 | + middle_value = len(sortedlist) // 2 |
| 144 | + final = (sortedlist[middle_value] + sortedlist[~middle_value]) / 2 |
| 145 | + if chart.lower() == 'y': |
| 146 | + plt.scatter(final, final) |
| 147 | + plt.show() |
| 148 | + else: |
| 149 | + pass |
| 150 | + return final |
| 151 | + def exit(): |
| 152 | + sys.exit() |
| 153 | + def returnMode(list): |
| 154 | + sortedlist = sorted(list) |
| 155 | + avg = mode(sortedlist) |
| 156 | + return avg |
| 157 | + def returnMean(list): |
| 158 | + sortedlist = sorted(list) |
| 159 | + meannum = sum(sortedlist) / len(sortedlist) |
| 160 | + return meannum |
| 161 | + def |
| 162 | + |
| 163 | + |
| 164 | + |
| 165 | + |
| 166 | + |
| 167 | + |
| 168 | + |
| 169 | + |
| 170 | + |
| 171 | + |
| 172 | + |
| 173 | + |
| 174 | + |
| 175 | + |
| 176 | + |
| 177 | + |
| 178 | + custom_features = { |
| 179 | + |
| 180 | + } |
| 181 | + |
| 182 | + with open(file, "rb") as source: |
| 183 | + tokens = [] |
| 184 | + for token in tokenize.tokenize(source.readline): |
| 185 | + if token.string in keys: |
| 186 | + t = (token.type, keys[token.string]) |
| 187 | + elif token.string in custom_features: |
| 188 | + t = (token.type, token.string) |
| 189 | + else: |
| 190 | + t = (token.type, token.string) |
| 191 | + tokens.append(t) |
| 192 | + |
| 193 | + code = tokenize.untokenize(tokens).decode("utf-8") |
| 194 | + exec(code) |
| 195 | + |
| 196 | + for feature_name, feature_func in custom_features.items(): |
| 197 | + if feature_name in globals(): |
| 198 | + feature_func() |
| 199 | + |
| 200 | + |
| 201 | +print("VisualScipt\nEnter a filename or license for license or help() for help or exit() to exit") |
| 202 | +if __name__ == "__main__": |
| 203 | + while True: |
| 204 | + filename = input(">>> ") |
| 205 | + if filename.lower() == 'exit()': |
| 206 | + break |
| 207 | + elif filename.lower() == 'help()': |
| 208 | + print("\nexit() to exit or enter to go back\n") |
| 209 | + elif filename.lower() == 'license': |
| 210 | + print("\nVisualScript is lisensed under a MIT license.\nRead the terms here:\nhttps://github.com/Bruceli-iscool/VisualScript/blob/main/LICENSE\n") |
| 211 | + try: |
| 212 | + process_code(filename) |
| 213 | + except Exception as e: |
| 214 | + if len(filename) < 1 or filename == 'help()' or filename == 'license': |
| 215 | + pass |
| 216 | + else: |
| 217 | + print(f"An error occurred: {e}") |
| 218 | + |
0 commit comments