feat : random equations mode added #32

pull/79/head
sepandhaghighi 2021-12-14 18:43:34 +03:30
rodzic c300562ffa
commit c69edd5a07
3 zmienionych plików z 30 dodań i 2 usunięć

Wyświetl plik

@ -7,8 +7,27 @@ import json
from .params import Projection, DEFAULT_PROJECTION, VALID_COLORS, NFT_STORAGE_API, OVERVIEW
from .params import DATA_TYPE_ERROR, DATA_PARSING_ERROR, NO_FIG_ERROR_MESSAGE
from .params import FIG_SAVE_SUCCESS_MESSAGE, NFT_STORAGE_SUCCESS_MESSAGE, DATA_SAVE_SUCCESS_MESSAGE
from .params import ELEMENTS_LIST, ARGUMENT_LIST, OPERATORS_LIST
from .errors import samilaDataError
def random_equation_gen():
"""
Generate random equation.
:return: equation as str
"""
num_elements = random.randint(2,len(ELEMENTS_LIST) + 3)
result = ""
index = 1
while(index<=num_elements):
random_coef1 = "random.uniform(-1,1)"
argument = random.choice(ARGUMENT_LIST)
result = result + random.choice(ELEMENTS_LIST).format(str(random_coef1),argument)
if index<num_elements:
result = result + random.choice(OPERATORS_LIST)
index = index + 1
return result
def float_range(start, stop, step):
"""

Wyświetl plik

@ -4,7 +4,8 @@ import random
import itertools
import matplotlib
import matplotlib.pyplot as plt
from .functions import float_range, filter_color, filter_projection, nft_storage_upload, save_data_file, save_fig_file, save_fig_buf, load_data
from .functions import float_range, filter_color, filter_projection, nft_storage_upload
from .functions import save_data_file, save_fig_file, save_fig_buf, load_data, random_equation_gen
from .errors import samilaGenerateError
from .params import *
from warnings import warn
@ -34,7 +35,8 @@ class GenerativeImage:
"""
if function1 is None or function2 is None:
if data is None:
warn(NOTHING_PROVIDED_WARNING, RuntimeWarning)
self.function1 = eval("lambda x,y:" + random_equation_gen())
self.function2 = eval("lambda x,y:" + random_equation_gen())
else:
warn(JUST_DATA_WARNING, RuntimeWarning)
if data is not None:

Wyświetl plik

@ -50,3 +50,10 @@ class Projection(Enum):
LAMBERT = "lambert"
MOLLWEIDE = "mollweide"
RECTILINEAR = "rectilinear"
ELEMENTS_LIST = ["{0}*math.cos({1})","{0}*math.sin({1})","{0}*{1}","{0}*abs({1})","{0}*math.ceil({1})","{0}*math.floor({1})"]
ARGUMENT_LIST = ["x*y","x","y","y-x","x-y","x+y","x**2","y**2","(x**2)*y","(y**2)*x","(x**2)*(y**3)","(x**3)*(y**2)","x*(y**3)","y*(x**3)"]
OPERATORS_LIST = ["+","-"]