Merge pull request #55 from sepandhaghighi/dev

Version 0.2
pull/85/head v0.2
Sepand Haghighi 2021-10-14 12:20:13 +03:30 zatwierdzone przez GitHub
commit 558f8ef032
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
30 zmienionych plików z 499 dodań i 33 usunięć

10
.coveragerc 100644
Wyświetl plik

@ -0,0 +1,10 @@
[run]
branch = True
omit =
*/samila/__main__.py
*/samila/__init__.py
*/samila/test.py
[report]
# Regexes for lines to exclude from consideration
exclude_lines =
pragma: no cover

9
.github/dependabot.yml vendored 100644
Wyświetl plik

@ -0,0 +1,9 @@
version: 2
updates:
- package-ecosystem: pip
directory: "/"
schedule:
interval: weekly
time: "01:30"
open-pull-requests-limit: 10
target-branch: dev

37
.github/workflows/test1.yml vendored 100644
Wyświetl plik

@ -0,0 +1,37 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
name: CI (Main)
on: [push, pull_request]
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
python-version: [3.5, 3.6, 3.7, 3.8, 3.9]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install package
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
python setup.py install
- name: First test
run: |
python -m samila
- name: Test requirements Installation
run: |
python otherfiles/requirements-splitter.py
pip install --upgrade --upgrade-strategy=only-if-needed -r test-requirements.txt
- name: Test with pytest
run: |
python -m pytest --ignore-glob="*nft_upload_test.py" test --cov=samila --cov-report=term
if: matrix.python-version != 3.5

Wyświetl plik

@ -1,18 +1,18 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
name: CI
name: CI (NFT Upload + Other)
on: [push, pull_request]
jobs:
build:
runs-on: ${{ matrix.os }}
environment: TEST_SECRET
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
python-version: [3.5, 3.6, 3.7, 3.8, 3.9]
os: [ubuntu-latest]
python-version: [3.7]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
@ -24,16 +24,26 @@ jobs:
python -m pip install --upgrade pip
pip install -r requirements.txt
python setup.py install
- name: Install dev-requirements
- name: First test
run: |
pip install --upgrade --upgrade-strategy=only-if-needed -r dev-requirements.txt
python -m samila
- name: Test requirements Installation
run: |
python otherfiles/requirements-splitter.py
pip install --upgrade --upgrade-strategy=only-if-needed -r test-requirements.txt
- name: Test with pytest (+ NFT upload test)
run: |
python -m pytest test --cov=samila --cov-report=term
env:
NFT_STORAGE_API_KEY: ${{ secrets.NFT_STORAGE_API_KEY }}
- name: Version check
run: |
python otherfiles/version_check.py
if: matrix.python-version == 3.7
- name: Other tests
run: |
python -m vulture samila/ setup.py --min-confidence 65 --exclude=__init__.py --sort-by-size
python -m bandit -r samila -s B311
python -m pydocstyle --match='(?!test).*\.py' -v
if: matrix.python-version == 3.7
python -m pydocstyle -v --match-dir=samila
- name: Codecov
run: |
codecov

Wyświetl plik

@ -5,6 +5,21 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
## [Unreleased]
## [0.2] - 2021-10-14
### Added
- `dependabot.yml`
- `requirements-splitter.py`
- `samila_help` function
- `test.py`
- `function_test.py`
- `is_same_data` function
- `save_image` method
### Changed
- `dev-requirements.txt` updated
- `README.md` updated
- `__main__.py` updated
- `test.yml` updated
- `nft_storage` method updated
## [0.1] - 2021-09-30
### Added
- `GenerativeImage` class
@ -12,7 +27,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- `generate` method
- `nft_storage` method
[Unreleased]: https://github.com/sepandhaghighi/samila/compare/v0.1...dev
[Unreleased]: https://github.com/sepandhaghighi/samila/compare/v0.2...dev
[0.2]: https://github.com/sepandhaghighi/samila/compare/v0.1...v0.2
[0.1]: https://github.com/sepandhaghighi/samila/compare/1058677...v0.1

Wyświetl plik

@ -1,6 +1,7 @@
<div align="center">
<h1>Samila</h1>
<img src="https://github.com/sepandhaghighi/samila/raw/master/otherfiles/logo.png" width=400 height=400>
<br/>
<h1>Samila</h1>
<br/>
<a href="https://www.python.org/"><img src="https://img.shields.io/badge/built%20with-Python3-green.svg" alt="built with Python3" /></a>
<a href="https://codecov.io/gh/sepandhaghighi/samila">
@ -14,6 +15,7 @@
* [Overview](https://github.com/sepandhaghighi/samila#overview)
* [Installation](https://github.com/sepandhaghighi/samila#installation)
* [Usage](https://github.com/sepandhaghighi/samila#usage)
* [Mathematical Details](https://github.com/sepandhaghighi/samila#mathematical-details)
* [Issues & Bug Reports](https://github.com/sepandhaghighi/samila#issues--bug-reports)
* [Dependencies](https://github.com/sepandhaghighi/samila#dependencies)
* [Contribution](https://github.com/sepandhaghighi/samila/blob/master/.github/CONTRIBUTING.md)
@ -38,7 +40,7 @@ Samila is a generative art generator written in Python, Samila let's you create
</tr>
<tr>
<td align="center">PyPI Counter</td>
<td align="center"><a href="http://pepy.tech/count/samila"><img src="http://pepy.tech/badge/samila"></a></td>
<td align="center"><a href="http://pepy.tech/project/samila"><img src="http://pepy.tech/badge/samila"></a></td>
</tr>
<tr>
<td align="center">Github Stars</td>
@ -65,6 +67,9 @@ Samila is a generative art generator written in Python, Samila let's you create
<table>
<tr>
<td align="center">Code Quality</td>
<td><a href="https://www.codacy.com/gh/sepandhaghighi/samila/dashboard?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=sepandhaghighi/samila&amp;utm_campaign=Badge_Grade"><img src="https://app.codacy.com/project/badge/Grade/14df8ed5f8434aaea85889555b0182a9"/></a></td>
<td><a href="https://codebeat.co/projects/github-com-sepandhaghighi-samila-dev"><img alt="codebeat badge" src="https://codebeat.co/badges/01e6aa48-4cc2-4d9c-8288-c9fb490ad371" /></a></td>
<td><a href="https://www.codefactor.io/repository/github/sepandhaghighi/samila"><img src="https://www.codefactor.io/repository/github/sepandhaghighi/samila/badge" alt="CodeFactor" /></a></td>
</tr>
</table>
@ -74,7 +79,7 @@ Samila is a generative art generator written in Python, Samila let's you create
### Source code
- Download [Version 0.1](https://github.com/sepandhaghighi/samila/archive/v0.1.zip) or [Latest Source ](https://github.com/sepandhaghighi/samila/archive/dev.zip)
- Download [Version 0.2](https://github.com/sepandhaghighi/samila/archive/v0.2.zip) or [Latest Source ](https://github.com/sepandhaghighi/samila/archive/dev.zip)
- Run `pip install -r requirements.txt` or `pip3 install -r requirements.txt` (Need root access)
- Run `python3 setup.py install` or `python setup.py install` (Need root access)
@ -82,7 +87,7 @@ Samila is a generative art generator written in Python, Samila let's you create
- Check [Python Packaging User Guide](https://packaging.python.org/installing/)
- Run `pip install samila==0.1` or `pip3 install samila==0.1` (Need root access)
- Run `pip install samila==0.2` or `pip3 install samila==0.2` (Need root access)
### Easy install
@ -169,6 +174,48 @@ Upload generated image directly to [NFT.storage](https://NFT.storage)
{'status': True, 'message': 'Everything seems good'}
```
### Save
Save generated image
```pycon
>>> g.save_image(file_adr="test.png")
{'status': True, 'message': 'Everything seems good'}
```
## Mathematical details
Samila is simply a transformation between a square-shaped space from the Cartesian coordinate system to any arbitrary coordination like [Polar coordinate system](https://en.wikipedia.org/wiki/Polar_coordinate_system).
### Example
<img src="https://github.com/sepandhaghighi/samila/raw/master/otherfiles/mathematical_details/transformation.png">
We have set of points in the first space (left square) which can be define as follow:
<img src="https://github.com/sepandhaghighi/samila/raw/master/otherfiles/mathematical_details/S1.jpg">
And bellow functions are used for transformation:
```pycon
>>> def f1(x,y):
result = random.uniform(-1,1) * x**2 - math.sin(y**2) + abs(y-x)
return result
>>> def f2(x,y):
result = random.uniform(-1,1) * y**3 - math.cos(x**2) + 2*x
return result
```
<img src="https://github.com/sepandhaghighi/samila/raw/master/otherfiles/mathematical_details/S2.jpg">
here we uses `Projection.POLAR` so later space will be the polar space and we have:
```pycon
>>> g = GenerativeImage(f1,f2)
>>> g.generate(seed=10)
>>> g.plot(projection=Projection.POLAR)
```
<img src="https://github.com/sepandhaghighi/samila/raw/master/otherfiles/mathematical_details/S2_.jpg">
<img src="https://github.com/sepandhaghighi/samila/raw/master/otherfiles/images/6.png">
## Issues & bug reports
Just fill an issue and describe it. We'll check it ASAP!
@ -193,7 +240,11 @@ or send an email to [info@4r7.ir](mailto:info@4r7.ir "info@4r7.ir").
## References
<blockquote>1- </blockquote>
<blockquote>1- Schönlieb, Carola-Bibiane, and Franz Schubert. "Random simulations for generative art construction–some examples." Journal of Mathematics and the Arts 7.1 (2013): 29-39.</blockquote>
<blockquote>2- <a href="https://github.com/cutterkom/generativeart">Create Generative Art with R</a></blockquote>
<blockquote>3- <a href="https://nft.storage/">NFT.storage : Free decentralized storage and bandwidth for NFTs</a></blockquote>
## Show your support
@ -224,8 +275,13 @@ bnb1zglwcf0ac3d0s2f6ck5kgwvcru4tlctt4p5qef
0xcD4Db18B6664A9662123D4307B074aE968535388
<h4>Dash</h4>
Xd3Yn2qZJ7VE8nbKw2fS98aLxR5M6WUU3s
<h4>Stellar</h4>
<h4>Stellar</h4>
GALPOLPISRHIYHLQER2TLJRGUSZH52RYDK6C3HIU4PSMNAV65Q36EGNL
<h4>Zilliqa</h4>
zil1knmz8zj88cf0exr2ry7nav9elehxfcgqu3c5e5
<h4>Coffeete</h4>
<a href="http://www.coffeete.ir/opensource">
<img src="http://www.coffeete.ir/images/buttons/lemonchiffon.png" style="width:260px;" />
</a>

14
codecov.yml 100644
Wyświetl plik

@ -0,0 +1,14 @@
codecov:
require_ci_to_pass: yes
coverage:
precision: 2
round: up
range: "70...100"
status:
patch:
default:
enabled: no
project:
default:
threshold: 1%

Wyświetl plik

@ -1,5 +1,11 @@
matplotlib==3.0.0
art==5.2
vulture>=1.0
bandit>=1.5.1
pydocstyle>=3.0.0
setuptools>=40.8.0
codecov>=2.0.15
coverage>=4.1
pytest>=4.3.1
pytest-cov>=2.6.1

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 282 KiB

BIN
otherfiles/logo.png 100644

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 191 KiB

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 6.8 KiB

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 8.8 KiB

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 18 KiB

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 215 KiB

Wyświetl plik

@ -0,0 +1,12 @@
# -*- coding: utf-8 -*-
"""Requirements splitter."""
test_req = ""
with open('dev-requirements.txt', 'r') as f:
for line in f:
if '==' not in line:
test_req += line
with open('test-requirements.txt', 'w') as f:
f.write(test_req)

Wyświetl plik

@ -4,7 +4,7 @@ import os
import sys
import codecs
Failed = 0
SAMILA_VERSION = "0.1"
SAMILA_VERSION = "0.2"
SETUP_ITEMS = [

4
pytest.ini 100644
Wyświetl plik

@ -0,0 +1,4 @@
# content of pytest.ini
[pytest]
addopts = --doctest-modules
doctest_optionflags= NORMALIZE_WHITESPACE IGNORE_EXCEPTION_DETAIL

Wyświetl plik

@ -1,2 +1,3 @@
matplotlib>=3.0.0
requests>=2.20.0
art>=1.8

Wyświetl plik

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
"""Samila modules."""
from .genimage import GenerativeImage
from .params import Projection,VALID_COLORS
from .params import Projection, VALID_COLORS, SAMILA_VERSION
__version__ = SAMILA_VERSION

Wyświetl plik

@ -1,2 +1,11 @@
# -*- coding: utf-8 -*-
"""Samila main."""
from art import tprint
from .params import SAMILA_VERSION
from .functions import samila_help
if __name__ == "__main__":
tprint("samila")
tprint("V:" + SAMILA_VERSION)
samila_help()

Wyświetl plik

@ -2,7 +2,9 @@
"""Samila functions."""
import requests
from .params import Projection, DEFAULT_PROJECTION, VALID_COLORS, NFT_STORAGE_API, NFT_STORAGE_SUCCESS_MESSAGE
import io
from .params import Projection, DEFAULT_PROJECTION, VALID_COLORS, NFT_STORAGE_API, NFT_STORAGE_SUCCESS_MESSAGE, FIG_SAVE_SUCCESS_MESSAGE, NO_FIG_ERROR_MESSAGE, OVERVIEW
def float_range(start, stop, step):
"""
@ -68,6 +70,7 @@ def filter_color(color):
return VALID_COLORS[distance_list.index(min_distance)]
return None
def filter_projection(projection):
"""
Filter given projection.
@ -80,6 +83,7 @@ def filter_projection(projection):
return projection.value
return DEFAULT_PROJECTION
def nft_storage_upload(api_key, data):
"""
Upload file to nft.storage.
@ -93,7 +97,10 @@ def nft_storage_upload(api_key, data):
result = {"status": True, "message": NFT_STORAGE_SUCCESS_MESSAGE}
try:
headers = {'Authorization': 'Bearer {0}'.format(api_key)}
response = requests.post(url=NFT_STORAGE_API,data=data,headers=headers)
response = requests.post(
url=NFT_STORAGE_API,
data=data,
headers=headers)
response_json = response.json()
if response_json["ok"]:
return result
@ -105,3 +112,75 @@ def nft_storage_upload(api_key, data):
result["message"] = str(e)
return result
def save_fig_file(figure, file_adr):
"""
Save figure as file.
:param figure: matplotlib figure
:type figure: matplotlib.figure.Figure
:param file_adr: file addresses
:type file_adr: str
:return: result as dict
"""
if figure is None:
return {"status": False, "message": NO_FIG_ERROR_MESSAGE}
result = {"status": True, "message": FIG_SAVE_SUCCESS_MESSAGE}
try:
figure.savefig(file_adr)
return result
except Exception as e:
result["status"] = False
result["message"] = str(e)
return result
def save_fig_buf(figure):
"""
Save figure as buffer.
:param figure: matplotlib figure
:type figure: matplotlib.figure.Figure
:return: result as dict
"""
if figure is None:
return {"status": False, "message": NO_FIG_ERROR_MESSAGE}
result = {
"status": True,
"message": FIG_SAVE_SUCCESS_MESSAGE,
"buffer": None}
try:
buf = io.BytesIO()
figure.savefig(buf, format='png')
result["buffer"] = buf
return result
except Exception as e:
result["status"] = False
result["message"] = str(e)
return result
def samila_help():
"""
Print samila details.
:return: None
"""
print(OVERVIEW)
print("Repo : https://github.com/sepandhaghighi/samila")
def is_same_data(data1, data2, precision=10**-5):
"""
Compare two data to be the same.
:param data1: given data1
:type data1: list
:param data2: given data2
:type data2: list
:param precision: comparing precision
:type precision: float
:return: True if they are the same
"""
is_same = map(lambda x, y: abs(x - y) < precision, data1, data2)
return all(is_same)

Wyświetl plik

@ -2,9 +2,8 @@
"""Samila generative image."""
import random
import itertools
import io
import matplotlib.pyplot as plt
from .functions import float_range, filter_color, filter_projection, nft_storage_upload
from .functions import float_range, filter_color, filter_projection, nft_storage_upload, save_fig_file, save_fig_buf
from .params import *
@ -108,7 +107,7 @@ class GenerativeImage:
ax.add_artist(ax.patch)
self.fig = fig
def nft_storage(self,api_key):
def nft_storage(self, api_key):
"""
Upload image to nft.storage.
@ -116,7 +115,19 @@ class GenerativeImage:
:type api_key: str
:return: result as dict
"""
buf = io.BytesIO()
self.fig.savefig(buf, format='png')
response = nft_storage_upload(api_key=api_key,data=buf.getvalue())
return response
response = save_fig_buf(self.fig)
if not response["status"]:
return {"status": False, "message": response["message"]}
buf = response["buffer"]
response = nft_storage_upload(api_key=api_key, data=buf.getvalue())
return response
def save_image(self, file_adr):
"""
Save generated image.
:param file_adr: file addresses
:type file_adr: str
:return: result as dict
"""
return save_fig_file(figure=self.fig, file_adr=file_adr)

Wyświetl plik

@ -4,7 +4,14 @@ import math
from enum import Enum
from matplotlib import colors as mcolors
SAMILA_VERSION = "0.1" # pragma: no cover
SAMILA_VERSION = "0.2" # pragma: no cover
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.
'''
DEFAULT_START = -1 * math.pi
DEFAULT_STOP = math.pi
@ -17,8 +24,9 @@ DEFAULT_SPOT_SIZE = 0.01
DEFAULT_PROJECTION = None
VALID_COLORS = list(dict(mcolors.BASE_COLORS, **mcolors.CSS4_COLORS).keys())
NFT_STORAGE_API = "https://api.nft.storage/upload"
NFT_STORAGE_SUCCESS_MESSAGE = "Everything seems good"
NFT_STORAGE_SUCCESS_MESSAGE = "Everything seems good."
FIG_SAVE_SUCCESS_MESSAGE = "Everything seems good."
NO_FIG_ERROR_MESSAGE = "No figure was found. First run `generate` and `plot` methods."
class Projection(Enum):

17
samila/test.py 100644
Wyświetl plik

@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-
"""Basic test file."""
"""
>>> import random
>>> import math
>>> from samila import GenerativeImage
>>> def f1(x,y):
... result = random.uniform(-1,1) * x**2 - math.sin(y**2) + abs(y-x)
... return result
>>> def f2(x,y):
... result = random.uniform(-1,1) * y**3 - math.cos(x**2) + 2*x
... return result
>>> g = GenerativeImage(f1,f2)
>>> g.generate()
>>> g.plot()
"""

Wyświetl plik

@ -32,14 +32,14 @@ def read_description():
setup(
name='samila',
packages=['samila'],
version='0.1',
version='0.2',
description='Generative ART',
long_description=read_description(),
long_description_content_type='text/markdown',
author='Sepand Haghighi',
author_email='info@4r7.ir',
url='https://github.com/sepandhaghighi/samila',
download_url='https://github.com/sepandhaghighi/samila/tarball/v0.1',
download_url='https://github.com/sepandhaghighi/samila/tarball/v0.2',
keywords="generative-art art nft file nft-storage",
project_urls={
'Source': 'https://github.com/sepandhaghighi/samila',
@ -48,9 +48,18 @@ setup(
install_requires=get_requires(),
python_requires='>=3.5',
classifiers=[
'Development Status :: 3 - Alpha',
'Natural Language :: English',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
'Topic :: Games/Entertainment',
'Topic :: Multimedia',
'Topic :: Multimedia :: Graphics',
'Topic :: Multimedia :: Graphics :: 3D Modeling',
'Topic :: Multimedia :: Graphics :: 3D Rendering',
'Topic :: Scientific/Engineering',
'Topic :: Scientific/Engineering :: Mathematics',
'Topic :: Scientific/Engineering :: Visualization',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',

Wyświetl plik

@ -0,0 +1,31 @@
# -*- coding: utf-8 -*-
"""
>>> from samila.functions import *
>>> s = list(float_range(1,1.5,0.1))
>>> s
[1.0, 1.1, 1.2000000000000002, 1.3000000000000003, 1.4000000000000004]
>>> is_same_data(s,[1,1.1,1.2,1.3,1.4])
True
>>> is_same_data([1,1.1,1.2,1.3,1.4],[1,1.11,1.3,1.4,1.5])
False
>>> filter_color("yellow")
'yellow'
>>> filter_color((0.2,0.3,0.4))
(0.2, 0.3, 0.4)
>>> filter_color(2)
>>> filter_color(4)
>>> distance_calc("test","test1")
1
>>> distance_calc("te1st","test")
1
>>> distance_calc("test12","test234")
3
>>> samila_help()
<BLANKLINE>
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.
<BLANKLINE>
Repo : https://github.com/sepandhaghighi/samila
"""

Wyświetl plik

@ -0,0 +1,34 @@
# -*- coding: utf-8 -*-
"""
>>> import os
>>> import math
>>> import random
>>> import time
>>> from samila import GenerativeImage, Projection
>>> from samila.params import VALID_COLORS
>>> def f1(x,y):
... result = random.uniform(-1,1) * x**2 - math.sin(y**2) + abs(y-x)
... return result
>>> def f2(x,y):
... result = random.uniform(-1,1) * y**3 - math.cos(x**2) + 2*x
... return result
>>> g = GenerativeImage(f1,f2)
>>> g.generate()
>>> g.plot()
>>> NFT_STORAGE_API_KEY = os.environ["NFT_STORAGE_API_KEY"]
>>> g.generate()
>>> random_projection = random.choice(list(Projection))
>>> random_color = random.choice(VALID_COLORS)
>>> random_bgcolor = random.choice(VALID_COLORS)
>>> g.plot(projection=random_projection,color=random_color,bgcolor=random_bgcolor)
>>> counter = 0
>>> try_limit = 3
>>> status = False
>>> while(status == False and counter<try_limit):
... result = g.nft_storage(api_key=NFT_STORAGE_API_KEY)
... counter = counter + 1
... status = result["status"]
... time.sleep(1)
>>> status
True
"""

Wyświetl plik

@ -0,0 +1,92 @@
# -*- coding: utf-8 -*-
"""
>>> import random
>>> import math
>>> import os
>>> import pickle
>>> import socket
>>> def guard(*args, **kwargs):
... raise Exception("No internet connection!")
>>> from samila import GenerativeImage, Projection
>>> from samila.functions import is_same_data
>>> import pickle
>>> def f1(x,y):
... result = random.uniform(-1,1) * x**2 - math.sin(y**2) + abs(y-x)
... return result
>>> def f2(x,y):
... result = random.uniform(-1,1) * y**3 - math.cos(x**2) + 2*x
... return result
>>> g = GenerativeImage(f1,f2)
>>> g.function1 == f1
True
>>> g.function2 == f2
True
>>> g.fig
>>> g.generate()
>>> isinstance(g.data1, list)
True
>>> isinstance(g.data2, list)
True
>>> g.generate(seed=10, start=-2*math.pi, step=0.1, stop=math.pi/2)
>>> g.seed
10
>>> with open("test/test1_1_d1.pkl", "rb") as fp:
... temp_data = pickle.load(fp)
>>> is_same_data(g.data1, temp_data)
True
>>> with open("test/test1_1_d2.pkl", "rb") as fp:
... temp_data = pickle.load(fp)
>>> is_same_data(g.data2, temp_data)
True
>>> g.plot()
>>> result = g.save_image("test.png")
>>> result["status"]
True
>>> result["message"]
'Everything seems good.'
>>> g.plot(color='red')
>>> g.plot(color='red', bgcolor='black')
>>> result = g.save_image("test2.png")
>>> result["status"]
True
>>> result["message"]
'Everything seems good.'
>>> from samila import GenerativeImage, Projection
>>> g.plot(projection=Projection.POLAR, color='red', bgcolor='black')
>>> g.plot(projection=Projection.POLAR, color=(.1, .2, .8))
>>> g.plot(bgcolor=(.1, .2, .8), spot_size=0.1)
>>> g.plot(size=(20, 20))
>>> result = g.nft_storage(api_key="")
>>> result['status']
False
>>> result['message']
'API Key is missing, make sure the `Authorization` header has a value in the following format `Bearer {api key}`.'
>>> g = GenerativeImage(f1,f2)
>>> result = g.nft_storage(api_key="")
>>> result["status"]
False
>>> result["message"]
'No figure was found. First run `generate` and `plot` methods.'
>>> result = g.save_image(file_adr="")
>>> result["status"]
False
>>> result["message"]
'No figure was found. First run `generate` and `plot` methods.'
>>> g.fig = 2
>>> result = g.nft_storage(api_key="")
>>> result['status']
False
>>> result = g.save_image(file_adr="")
>>> result["status"]
False
>>> socket.socket = guard
>>> g.generate()
>>> g.plot(color=2,bgcolor=2)
>>> result = g.nft_storage("")
>>> result["status"]
False
>>> result["message"]
'No internet connection!'
>>> os.remove("test.png")
>>> os.remove("test2.png")
"""

BIN
test/test1_1_d1.pkl 100644

Plik binarny nie jest wyświetlany.

BIN
test/test1_1_d2.pkl 100644

Plik binarny nie jest wyświetlany.