samila/samila/params.py

167 wiersze
4.7 KiB
Python
Czysty Zwykły widok Historia

2021-09-20 19:58:52 +00:00
# -*- coding: utf-8 -*-
"""Samila params."""
2021-09-26 20:40:20 +00:00
import math
2021-09-28 11:46:15 +00:00
from enum import Enum
from matplotlib import colors as mcolors
from matplotlib import cm
2021-09-26 20:40:20 +00:00
2022-12-09 14:15:56 +00:00
SAMILA_VERSION = "1.0" # pragma: no cover
2021-09-29 15:32:44 +00:00
2021-10-05 09:59:53 +00:00
OVERVIEW = '''
Samila is a generative art generator written in Python, Samila let's you
create arts based on many thousand points. The position of every single
point is calculated by a formula, which has random parameters.
Because of the random numbers, every image looks different.
'''
2021-09-26 20:40:20 +00:00
DEFAULT_START = -1 * math.pi
DEFAULT_STOP = math.pi
DEFAULT_STEP = 0.01
DEFAULT_COLOR = "black"
2021-09-28 06:21:31 +00:00
DEFAULT_BACKGROUND_COLOR = "white"
DEFAULT_CMAP = cm.get_cmap("viridis", 256)
DEFAULT_CMAP_RANGE = 256
DEFAULT_ALPHA = 0.1
DEFAULT_LINEWIDTH = 1.5
2021-09-27 07:18:06 +00:00
DEFAULT_IMAGE_SIZE = (10, 10)
2021-09-26 20:40:20 +00:00
DEFAULT_SPOT_SIZE = 0.01
DEFAULT_DEPTH = 1
DEFAULT_ROTATION = 0.0
Config json Added (#80) * fix : typo fixed in docstring. * unifx : never mind :). * remove : extra lines removed from Magic section. * add : samilaConfigError added. * edit : DEFAULT_PROJECTION edited. * add : CONFIG_TYPE_ERROR added. * add : filter_float function added. * add : save_config_file function added. * add : load_config function added. * add : minor imports addded to functions.py. * add : some imports added to genimage.py. * fix : whitespace removed. * add : config parameter added. * add : save_config method added. * edit : minor edits in genimage.py. * edit : minor edits in save/load config. * edit: minor edits in save/load config. * add : filter_size added to functions. * update : minor updated due to last change. * edit : minor edit in filter_size. * add : plot_params_filter function added. * add : generate_params_filter added. * remove : unneccessary errors and warnings removed. * update : GenerativeImage __init__ updated due to last commit. * add : _GI_initializer added. * edit : make load_data structure similar to load_config. * fix : typo fixed in functions. * test : some tests added. * test : tests added for warning. * fix : minor bug fixed. * add : filter_size tests added. * add : error tests added. * add : save_config part added. * fix : typo fixed. * tests : minor tests added. * move : function[12]_str moved to __init__ root. * fix : typo fixed in errors.py. * fix : typo fixed in README.md. * fix : typo fixed in CHANGELOG.md. * add : matplotlib_version attribute added. * add : samilaPlotError added. * add : PLOT_DATA_ERROR added. * update : minor updates due to latest changes. * remove : extra tests removed. * edit : PLOT_DATA_ERROR edited. * test : tests added. * edit : minor edits in save_config/data. * add : new error messages added. * test : tests added. * fix : typo fixed. * replace : DATA_NO_DATA_ERROR -> SAVE_NO_DATA_ERROR. * edit : minor edits in plot_params_filter function. * add : two parameter added. * edit : __init__ docstring edited. * fix : typo fixed in genimage. * fix : typo fixed in params.py. * fix : typo fixed in tests. * fix : typo fixed in CHANGELOG.md.
2022-01-04 15:24:12 +00:00
DEFAULT_PROJECTION = "rectilinear"
DEFAULT_MARKER = "."
Config json Added (#80) * fix : typo fixed in docstring. * unifx : never mind :). * remove : extra lines removed from Magic section. * add : samilaConfigError added. * edit : DEFAULT_PROJECTION edited. * add : CONFIG_TYPE_ERROR added. * add : filter_float function added. * add : save_config_file function added. * add : load_config function added. * add : minor imports addded to functions.py. * add : some imports added to genimage.py. * fix : whitespace removed. * add : config parameter added. * add : save_config method added. * edit : minor edits in genimage.py. * edit : minor edits in save/load config. * edit: minor edits in save/load config. * add : filter_size added to functions. * update : minor updated due to last change. * edit : minor edit in filter_size. * add : plot_params_filter function added. * add : generate_params_filter added. * remove : unneccessary errors and warnings removed. * update : GenerativeImage __init__ updated due to last commit. * add : _GI_initializer added. * edit : make load_data structure similar to load_config. * fix : typo fixed in functions. * test : some tests added. * test : tests added for warning. * fix : minor bug fixed. * add : filter_size tests added. * add : error tests added. * add : save_config part added. * fix : typo fixed. * tests : minor tests added. * move : function[12]_str moved to __init__ root. * fix : typo fixed in errors.py. * fix : typo fixed in README.md. * fix : typo fixed in CHANGELOG.md. * add : matplotlib_version attribute added. * add : samilaPlotError added. * add : PLOT_DATA_ERROR added. * update : minor updates due to latest changes. * remove : extra tests removed. * edit : PLOT_DATA_ERROR edited. * test : tests added. * edit : minor edits in save_config/data. * add : new error messages added. * test : tests added. * fix : typo fixed. * replace : DATA_NO_DATA_ERROR -> SAVE_NO_DATA_ERROR. * edit : minor edits in plot_params_filter function. * add : two parameter added. * edit : __init__ docstring edited. * fix : typo fixed in genimage. * fix : typo fixed in params.py. * fix : typo fixed in tests. * fix : typo fixed in CHANGELOG.md.
2022-01-04 15:24:12 +00:00
SEED_LOWER_BOUND = 0
SEED_UPPER_BOUND = 2**20
VALID_COLORS = list(dict(mcolors.BASE_COLORS, **mcolors.CSS4_COLORS).keys())
HEX_COLOR_PATTERN = r'^#(?:[0-9a-fA-F]{3}){1,2}$'
NFT_STORAGE_API = "https://api.nft.storage/upload"
NFT_STORAGE_LINK = "https://ipfs.io/ipfs/{}"
NFT_STORAGE_SUCCESS_MESSAGE = "Everything seems good."
2021-10-12 12:50:50 +00:00
FIG_SAVE_SUCCESS_MESSAGE = "Everything seems good."
2021-10-22 09:28:52 +00:00
DATA_SAVE_SUCCESS_MESSAGE = "Everything seems good."
NO_FIG_ERROR_MESSAGE = "No figure was found. First run `generate` and `plot` methods."
2021-10-22 09:19:40 +00:00
DATA_TYPE_ERROR = "Provided data file is not supported. It should be either file or io.IOBase."
DATA_FORMAT_ERROR = "Provided data file is not supported. It should include data1 and data2."
Config json Added (#80) * fix : typo fixed in docstring. * unifx : never mind :). * remove : extra lines removed from Magic section. * add : samilaConfigError added. * edit : DEFAULT_PROJECTION edited. * add : CONFIG_TYPE_ERROR added. * add : filter_float function added. * add : save_config_file function added. * add : load_config function added. * add : minor imports addded to functions.py. * add : some imports added to genimage.py. * fix : whitespace removed. * add : config parameter added. * add : save_config method added. * edit : minor edits in genimage.py. * edit : minor edits in save/load config. * edit: minor edits in save/load config. * add : filter_size added to functions. * update : minor updated due to last change. * edit : minor edit in filter_size. * add : plot_params_filter function added. * add : generate_params_filter added. * remove : unneccessary errors and warnings removed. * update : GenerativeImage __init__ updated due to last commit. * add : _GI_initializer added. * edit : make load_data structure similar to load_config. * fix : typo fixed in functions. * test : some tests added. * test : tests added for warning. * fix : minor bug fixed. * add : filter_size tests added. * add : error tests added. * add : save_config part added. * fix : typo fixed. * tests : minor tests added. * move : function[12]_str moved to __init__ root. * fix : typo fixed in errors.py. * fix : typo fixed in README.md. * fix : typo fixed in CHANGELOG.md. * add : matplotlib_version attribute added. * add : samilaPlotError added. * add : PLOT_DATA_ERROR added. * update : minor updates due to latest changes. * remove : extra tests removed. * edit : PLOT_DATA_ERROR edited. * test : tests added. * edit : minor edits in save_config/data. * add : new error messages added. * test : tests added. * fix : typo fixed. * replace : DATA_NO_DATA_ERROR -> SAVE_NO_DATA_ERROR. * edit : minor edits in plot_params_filter function. * add : two parameter added. * edit : __init__ docstring edited. * fix : typo fixed in genimage. * fix : typo fixed in params.py. * fix : typo fixed in tests. * fix : typo fixed in CHANGELOG.md.
2022-01-04 15:24:12 +00:00
CONFIG_TYPE_ERROR = "Provided config file is not supported. It should be either file or io.IOBase."
CONFIG_FORMAT_ERROR = "Provided config file is not supported. It should include f1 and f2."
Config json Added (#80) * fix : typo fixed in docstring. * unifx : never mind :). * remove : extra lines removed from Magic section. * add : samilaConfigError added. * edit : DEFAULT_PROJECTION edited. * add : CONFIG_TYPE_ERROR added. * add : filter_float function added. * add : save_config_file function added. * add : load_config function added. * add : minor imports addded to functions.py. * add : some imports added to genimage.py. * fix : whitespace removed. * add : config parameter added. * add : save_config method added. * edit : minor edits in genimage.py. * edit : minor edits in save/load config. * edit: minor edits in save/load config. * add : filter_size added to functions. * update : minor updated due to last change. * edit : minor edit in filter_size. * add : plot_params_filter function added. * add : generate_params_filter added. * remove : unneccessary errors and warnings removed. * update : GenerativeImage __init__ updated due to last commit. * add : _GI_initializer added. * edit : make load_data structure similar to load_config. * fix : typo fixed in functions. * test : some tests added. * test : tests added for warning. * fix : minor bug fixed. * add : filter_size tests added. * add : error tests added. * add : save_config part added. * fix : typo fixed. * tests : minor tests added. * move : function[12]_str moved to __init__ root. * fix : typo fixed in errors.py. * fix : typo fixed in README.md. * fix : typo fixed in CHANGELOG.md. * add : matplotlib_version attribute added. * add : samilaPlotError added. * add : PLOT_DATA_ERROR added. * update : minor updates due to latest changes. * remove : extra tests removed. * edit : PLOT_DATA_ERROR edited. * test : tests added. * edit : minor edits in save_config/data. * add : new error messages added. * test : tests added. * fix : typo fixed. * replace : DATA_NO_DATA_ERROR -> SAVE_NO_DATA_ERROR. * edit : minor edits in plot_params_filter function. * add : two parameter added. * edit : __init__ docstring edited. * fix : typo fixed in genimage. * fix : typo fixed in params.py. * fix : typo fixed in tests. * fix : typo fixed in CHANGELOG.md.
2022-01-04 15:24:12 +00:00
CONFIG_NO_STR_FUNCTION_ERROR = "Config file can't be saved. At least one of the function1_str or function2_str is None."
PLOT_DATA_ERROR = "Plotting process can't be Done because data{0} is empty. Use generate method first."
COLOR_SIZE_ERROR = "Color list size is not equal to the data size."
Config json Added (#80) * fix : typo fixed in docstring. * unifx : never mind :). * remove : extra lines removed from Magic section. * add : samilaConfigError added. * edit : DEFAULT_PROJECTION edited. * add : CONFIG_TYPE_ERROR added. * add : filter_float function added. * add : save_config_file function added. * add : load_config function added. * add : minor imports addded to functions.py. * add : some imports added to genimage.py. * fix : whitespace removed. * add : config parameter added. * add : save_config method added. * edit : minor edits in genimage.py. * edit : minor edits in save/load config. * edit: minor edits in save/load config. * add : filter_size added to functions. * update : minor updated due to last change. * edit : minor edit in filter_size. * add : plot_params_filter function added. * add : generate_params_filter added. * remove : unneccessary errors and warnings removed. * update : GenerativeImage __init__ updated due to last commit. * add : _GI_initializer added. * edit : make load_data structure similar to load_config. * fix : typo fixed in functions. * test : some tests added. * test : tests added for warning. * fix : minor bug fixed. * add : filter_size tests added. * add : error tests added. * add : save_config part added. * fix : typo fixed. * tests : minor tests added. * move : function[12]_str moved to __init__ root. * fix : typo fixed in errors.py. * fix : typo fixed in README.md. * fix : typo fixed in CHANGELOG.md. * add : matplotlib_version attribute added. * add : samilaPlotError added. * add : PLOT_DATA_ERROR added. * update : minor updates due to latest changes. * remove : extra tests removed. * edit : PLOT_DATA_ERROR edited. * test : tests added. * edit : minor edits in save_config/data. * add : new error messages added. * test : tests added. * fix : typo fixed. * replace : DATA_NO_DATA_ERROR -> SAVE_NO_DATA_ERROR. * edit : minor edits in plot_params_filter function. * add : two parameter added. * edit : __init__ docstring edited. * fix : typo fixed in genimage. * fix : typo fixed in params.py. * fix : typo fixed in tests. * fix : typo fixed in CHANGELOG.md.
2022-01-04 15:24:12 +00:00
SAVE_NO_DATA_ERROR = "Data file can't be saved. At least one of the data1 or data2 is None."
INVALID_COLOR_TYPE_ERROR = "Given color/bgcolor type is not supported."
VERSION_WARNING = "Your plots may differ as the version of matplotlib ({0}), Python ({1}), or Samila ({2}) that you are using is not the same as the source."
CALCULATION_EXCEPTION_WARNING = "The given functions are undefined at some points. Your plot may not be complete."
BOTH_COLOR_COMPLEMENT_WARNING = "It is not possible to set color and bgcolor to 'complement' at the same time! Both are automatically set to the previous or default selection."
COLOR_NOT_FOUND_WARNING = "color '{0}' not found. Replacing it with '{1}'"
2021-10-22 10:19:21 +00:00
2021-09-28 11:46:15 +00:00
class Projection(Enum):
2021-09-29 05:50:46 +00:00
"""
Samila Projection type class.
>>> projection = samila.Projection.POLAR
"""
2021-09-28 11:46:15 +00:00
DEFAULT = DEFAULT_PROJECTION
POLAR = "polar"
AITOFF = "aitoff"
HAMMER = "hammer"
LAMBERT = "lambert"
MOLLWEIDE = "mollweide"
2021-09-28 12:57:57 +00:00
RECTILINEAR = "rectilinear"
RANDOM = "random"
2021-12-14 15:13:34 +00:00
class Marker(Enum):
"""
Samila Marker type class.
>>> marker = samila.Marker.POINT
"""
DEFAULT = DEFAULT_MARKER
POINT = "."
PIXEL = ","
CIRCLE = "o"
TRIANGLE_DOWN = "v"
TRIANGLE_UP = "^"
TRIANGLE_LEFT = "<"
TRIANGLE_RIGHT = ">"
TRI_DOWN = "1"
TRI_UP = "2"
TRI_LEFT = "3"
TRI_RIGHT = "4"
OCTAGON = "8"
SQUARE = "s"
PENTAGON = "p"
PLUS = "+"
PLUS_FILLED = "P"
STAR = "*"
HEXAGON_VERTICAL = "h"
HEXAGON_HORIZONTAL = "H"
X = "x"
X_FILLED = "X"
DIAMOND = "D"
DIAMON_THIN = "d"
VLINE = "|"
HLINE = "_"
RANDOM = "random"
RANDOM_COEF_LIST = [
"random.uniform(-1,1)",
"random.gauss(0,1)",
"random.betavariate(1,1)",
"random.gammavariate(1,1)",
"random.lognormvariate(0,1)"]
2021-12-18 19:08:31 +00:00
ELEMENTS_LIST = [
"{0}*math.exp({1})",
"{0}*math.atan({1})",
"{0}*math.asinh({1})",
"{0}*math.acosh(abs({1})+1)",
"{0}*math.erf({1})",
2022-01-25 08:09:40 +00:00
"{0}*math.sqrt(abs({1}))",
"{0}*math.log(abs({1})+1)",
"{0}*math.tanh({1})",
2021-12-18 19:08:31 +00:00
"{0}*math.cos({1})",
"{0}*math.sin({1})",
"{0}*math.tan({1})",
2021-12-18 19:08:31 +00:00
"{0}*{1}",
"{0}/{1}",
2021-12-18 19:08:31 +00:00
"{0}*abs({1})",
"{0}*math.ceil({1})",
"{0}*math.floor({1})"]
2021-12-14 15:13:34 +00:00
2021-12-18 19:08:31 +00:00
ARGUMENTS_LIST = [
"x*y",
"x",
"y",
"1/x",
"1/y",
"x/y",
2021-12-18 19:08:31 +00:00
"y-x",
"x-y",
"x+y",
"x**3",
"y**3",
2021-12-18 19:08:31 +00:00
"x**2",
"y**2",
"(x**2)*y",
"(y**2)*x",
"(y**2)+(x**2)",
"(y**2)-(x**2)",
2021-12-18 19:08:31 +00:00
"(x**2)*(y**3)",
"(x**3)*(y**2)",
"x*(y**3)",
"y*(x**3)"]
2021-12-14 15:13:34 +00:00
OPERATORS_LIST = ["+", "-", "*", "/"]
RANDOM_EQUATION_MAX_COMPLEXITY = len(ELEMENTS_LIST) + 1
RANDOM_EQUATION_MIN_COMPLEXITY = 1
RANDOM_EQUATION_FOF_MAX_DEPTH = 3
RANDOM_EQUATION_FOF_MIN_DEPTH = 1