-
Notifications
You must be signed in to change notification settings - Fork 5
/
read_data.py
59 lines (51 loc) · 2.12 KB
/
read_data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# Copyright (c) 2018, Yaroslav Zotov, https://github.com/qiray/
# All rights reserved.
# This file is part of MathArtist.
# MathArtist is free software: you can redistribute it and/or modify
# 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.
# MathArtist 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 MathArtist. If not, see <https://www.gnu.org/licenses/>.
import parser
import re
from full_list import *
from coords import (linear_coord, tent_coord, sin_coord, polar, curved_rotate_coord,
rotate_coord, center)
def parse_formula(formula):
'''Parse formula and return it's code.'''
regex_x = re.compile(r"\bx\b")
regex_y = re.compile(r"\by\b")
try:
formula = regex_x.sub("VariableX()", formula)
formula = regex_y.sub("VariableY()", formula)
code = parser.expr(formula).compile()
return eval(code)
except:
return eval("VariableX()")
def read_file(filepath):
try:
f = open(filepath, "r")
use_depth = None
art = None
coord_transform = None
polar_shift = None
name = None
for line in f.readlines():
if line.startswith("Use depth:"):
use_depth = line.split(':')[1].replace(" ", "")
elif line.startswith("Coordinates transform:"):
coord_transform = line.split(':')[1].replace(" ", "")
elif line.startswith("Polar shift:"):
polar_shift = line.split(':')[1].replace(" ", "")
elif line.startswith("Formula:"):
art = line.split(':')[1].replace(" ", "")
elif line.startswith("Name:"):
name = line.split(':')[1]
return art, use_depth, coord_transform, polar_shift, name
except:
return "", "", "", None