Porównaj commity

...

27 Commity
v0.9 ... master

Autor SHA1 Wiadomość Data
Sepand Haghighi 6316e17d83
Version 1.1 (#187)
* rel : migrate to version 1.1

* fix : params.py revert
2023-04-05 18:03:36 +03:30
Sadra Sabouri 2a98624138
Samila version added for reproducibility (#184)
* change : micro version is no longer saved.

* add : `__version__` attribute for Samila version. (#171)

* fix : minor mistake in CHANGELOG.md.

* update : `VERSION_WARNING` updated.
2023-03-31 17:37:17 +03:30
dependabot[bot] a994902006
Bump art from 5.8 to 5.9 (#181)
Bumps [art](https://github.com/sepandhaghighi/art) from 5.8 to 5.9.
- [Release notes](https://github.com/sepandhaghighi/art/releases)
- [Changelog](https://github.com/sepandhaghighi/art/blob/master/CHANGELOG.md)
- [Commits](https://github.com/sepandhaghighi/art/compare/v5.8...v5.9)

---
updated-dependencies:
- dependency-name: art
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-03-27 12:17:11 +03:30
dependabot[bot] 74128ba966
Bump matplotlib from 3.7.0 to 3.7.1 (#180)
Bumps [matplotlib](https://github.com/matplotlib/matplotlib) from 3.7.0 to 3.7.1.
- [Release notes](https://github.com/matplotlib/matplotlib/releases)
- [Commits](https://github.com/matplotlib/matplotlib/compare/v3.7.0...v3.7.1)

---
updated-dependencies:
- dependency-name: matplotlib
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-03-27 03:38:20 +03:30
Sepand Haghighi be973ee183
Timeout (#182)
* fix : nft_storage_upload function updated

* doc : CHANGELOG updated

* fix : autopep8

* doc : README updated

* doc : minor edit in notebook flags

* fix : minor edit in style
2023-03-27 01:09:43 +03:30
Sadra Sabouri a54a5107a5
Rotation Added (#177)
* rotate : [INIT]

* edit : docstring edited.

* add : `rotate` function added.

* edit : docstring edited.

* add : `rotate` added to config and data files.

* log : changes logged.

* update : document updated.

* test : tests added (#176)

* add : `PIL` added to dependecies.

* fix : typo fixed in `requirements.txt`.

* remove : extra import in `genimage.py` removed.

* add : version for Pillow.

---------

Co-authored-by: sepandhaghighi <sepand.haghighi@yahoo.com>
2023-03-26 18:30:40 +03:30
dependabot[bot] e3c9cede8c
Bump matplotlib from 3.6.3 to 3.7.0 (#179)
Bumps [matplotlib](https://github.com/matplotlib/matplotlib) from 3.6.3 to 3.7.0.
- [Release notes](https://github.com/matplotlib/matplotlib/releases)
- [Commits](https://github.com/matplotlib/matplotlib/compare/v3.6.3...v3.7.0)

---
updated-dependencies:
- dependency-name: matplotlib
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-02-25 14:09:48 +03:30
omahs 74c36df546
Fix: minor typos (#178)
* Fix: minor typos

* Update CHANGELOG.md

* Update CHANGELOG.md

---------

Co-authored-by: Sepand Haghighi <sepand.haghighi@yahoo.com>
2023-02-24 23:44:56 +03:30
Sepand Haghighi 773b89aac9
Random mode modification (#175)
* fix : OPERATORS_LIST updated

* fix : random_equation_gen modified

* fix : RANDOM_EQUATION_GEN_FOF_MAX_DEPTH added

* fix : ELEMENTS_LIST updated

* fix : random equation generator params added

* fix : ARGUMENTS_LIST updated

* doc : CHANGELOG updated

* fix : autopep8
2023-01-19 12:09:33 +03:30
dependabot[bot] 3452354cd0
Bump matplotlib from 3.6.2 to 3.6.3 (#174)
Bumps [matplotlib](https://github.com/matplotlib/matplotlib) from 3.6.2 to 3.6.3.
- [Release notes](https://github.com/matplotlib/matplotlib/releases)
- [Commits](https://github.com/matplotlib/matplotlib/compare/v3.6.2...v3.6.3)

---
updated-dependencies:
- dependency-name: matplotlib
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-01-16 19:04:13 +03:30
Sepand Haghighi 54abe440af
Minor edit (#173)
* fix : load_config function modified

* doc : CHANGELOG updated
2023-01-08 21:09:39 +03:30
Sadra Sabouri a9e23235b2
Reproducibility Feature by Adding `python_version` (#172)
* add : `python_version` added.

* test : tests added.

* log : changes logged. (#171)

* fix : minor issues fixed.

* test : new test added for python version.

* fix : typo fixed in `genimage.py`.

* update : tests updated.
2023-01-06 10:36:21 +03:30
Sepand Haghighi 7e66936dc2
Merge pull request #169 from sepandhaghighi/dev
Version 1.0
2022-12-14 18:17:01 +03:30
sepandhaghighi 54d58497ef rel : migrate to version 1.0 2022-12-09 17:45:56 +03:30
Sepand Haghighi b38deb26c3
Random mode modification (#168)
* fix : RANDOM_EQUATION_GEN_COMPLEXITY added

* fix : ELEMENTS_LIST updated

* doc : CHANGELOG updated

* doc : dependencies section in README.md removed

* fix : ubuntu version fixed to 20.04
2022-12-09 17:28:44 +03:30
dependabot[bot] 9fb12259e0
Bump art from 5.7 to 5.8 (#166)
Bumps [art](https://github.com/sepandhaghighi/art) from 5.7 to 5.8.
- [Release notes](https://github.com/sepandhaghighi/art/releases)
- [Changelog](https://github.com/sepandhaghighi/art/blob/master/CHANGELOG.md)
- [Commits](https://github.com/sepandhaghighi/art/compare/v5.7...v5.8)

---
updated-dependencies:
- dependency-name: art
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-11-29 10:54:41 +03:30
Sadra Sabouri 36085c761b
Test (#167)
* fix : `status` issue fixed in tests.

* fix : `status["*"]` -> `result['status'][*]`
2022-11-29 01:58:20 +03:30
Sepand Haghighi 539547a7c1
Plot Warning (#165)
* fix : plot method updated

* doc : CHANGELOG updated
2022-11-27 16:07:43 +03:30
Sadra Sabouri f21f82c225
Data/Config Upload to IPFS (#164)
* add : `get_config` and `get_data`.

* add : `upload_data` and `upload_config` parameters added to `nft_storage` method.

* log : chages logged. (#144, #145)

* edit : config and data are now json dumped.

* doc : document updated.

* test : tests added.

* fix : minor issues fixed in tests.

* change : minor changes applied.

* test : test splited for inreasing coverage.
2022-11-22 13:01:58 +03:30
Sepand Haghighi b8967acc28
Generate method optimization (#163)
* fix : generate method optimized

* doc : CHANGELOG updated

* fix : missed_points_number added

* doc : CHANGELOG updated

* fix : tests updated
2022-11-10 17:52:52 +03:30
Sepand Haghighi a2729fb9ab
Python 3.11 support (#162)
* fix : Python 3.11 added to test.yml

* fix : Python 3.11 added to setup.py
2022-11-08 15:47:01 +03:30
Sepand Haghighi 5be1cc35fc
Minor edits (#161)
* fix : tests updated

* fix : tests updated

* fix : tests updated

* doc : minor edit in description
2022-11-08 08:22:13 +03:30
dependabot[bot] 3d1005185f
Bump matplotlib from 3.6.1 to 3.6.2 (#160)
Bumps [matplotlib](https://github.com/matplotlib/matplotlib) from 3.6.1 to 3.6.2.
- [Release notes](https://github.com/matplotlib/matplotlib/releases)
- [Commits](https://github.com/matplotlib/matplotlib/compare/v3.6.1...v3.6.2)

---
updated-dependencies:
- dependency-name: matplotlib
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-11-08 00:18:33 +03:30
Sadra Sabouri 27317de6c8
Marker Added (#159)
* add : `Marker` enum added. (#156)

* add : `marker` parameter added. (#156)

* log : changes logged. (#156)

* add : RANDOM marker added.

* change : minor change in docstring.

* add : `Marker` added to `__init__`.

* update : documents updated.

* test : tests added.

* edit : minor bugs fixed in tests.

* fix : minor typo fixed in demo.
2022-11-06 01:46:28 +03:30
dependabot[bot] daeafed59f
Bump matplotlib from 3.6.0 to 3.6.1 (#158)
Bumps [matplotlib](https://github.com/matplotlib/matplotlib) from 3.6.0 to 3.6.1.
- [Release notes](https://github.com/matplotlib/matplotlib/releases)
- [Commits](https://github.com/matplotlib/matplotlib/compare/v3.6.0...v3.6.1)

---
updated-dependencies:
- dependency-name: matplotlib
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-10-10 12:55:07 +03:30
Sepand Haghighi 9f32c783c9
Test (#157)
* fix : set Python 3.8 for tests

* doc : CHANGELOG updated
2022-10-07 22:27:57 +03:30
dependabot[bot] 3d361a466c
Bump matplotlib from 3.5.3 to 3.6.0 (#152)
Bumps [matplotlib](https://github.com/matplotlib/matplotlib) from 3.5.3 to 3.6.0.
- [Release notes](https://github.com/matplotlib/matplotlib/releases)
- [Commits](https://github.com/matplotlib/matplotlib/compare/v3.5.3...v3.6.0)

---
updated-dependencies:
- dependency-name: matplotlib
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-10-07 18:14:45 +03:30
18 zmienionych plików z 657 dodań i 156 usunięć

Wyświetl plik

@ -11,8 +11,8 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
python-version: [3.5, 3.6, 3.7, 3.8, 3.9, 3.10.0]
os: [ubuntu-20.04, windows-latest]
python-version: [3.5, 3.6, 3.7, 3.8, 3.9, 3.10.0, 3.11.0]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
@ -40,26 +40,26 @@ jobs:
python -m pytest test --cov=samila --cov-report=term
env:
NFT_STORAGE_API_KEY: ${{ secrets.NFT_STORAGE_API_KEY }}
if: matrix.python-version == 3.7 && matrix.os == 'ubuntu-latest'
if: matrix.python-version == 3.8 && matrix.os == 'ubuntu-20.04'
- name: Version check
run: |
python otherfiles/version_check.py
if: matrix.python-version == 3.7
if: matrix.python-version == 3.8
- 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,B307
python -m pydocstyle -v --match-dir=samila
if: matrix.python-version == 3.7
if: matrix.python-version == 3.8
- name: Notebook check
run: |
pip install notebook>=5.2.2
python otherfiles/notebook_check.py
if: matrix.python-version == 3.7 && matrix.os == 'ubuntu-latest'
if: matrix.python-version == 3.8 && matrix.os == 'ubuntu-20.04'
- name: Codecov
run: |
codecov
if: matrix.python-version == 3.7 && matrix.os == 'ubuntu-latest'
if: matrix.python-version == 3.8 && matrix.os == 'ubuntu-20.04'
- name: cProfile
run: |
python -m cProfile -s cumtime otherfiles/samila_profile.py

Wyświetl plik

@ -5,6 +5,40 @@ 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]
## [1.1] - 2023-04-05
### Added
- `__version__` attribute
- `python_version` attribute
- `get_python_version` function
- `RANDOM_EQUATION_MIN_COMPLEXITY` parameter
- `RANDOM_EQUATION_FOF_MAX_DEPTH` parameter
- `RANDOM_EQUATION_FOF_MIN_DEPTH` parameter
- `rotate` function
### Changed
- `rotation` parameter added to `plot` method
- `timeout` parameter added to `nft_storage` method
- `load_config` function modified
- `nft_storage_upload` function modified
- Random mode modified
- `RANDOM_EQUATION_GEN_COMPLEXITY` parameter renamed to `RANDOM_EQUATION_MAX_COMPLEXITY`
- `README.md` updated
## [1.0] - 2022-12-14
### Added
- `Marker` enum
- `get_data` function
- `get_config` function
### Changed
- `marker` parameter added to `plot` method
- `upload_data` parameter added to `nft_storage` method
- `upload_config` parameter added to `nft_storage` method
- `generate` method optimized
- Test system modified
- `README.md` updated
- `Python 3.11` added to `test.yml`
- `plot` method warning bug fixed
- Random mode modified
### Removed
- `fill_data` function
## [0.9] - 2022-09-28
### Added
- Anaconda workflow
@ -105,7 +139,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- `save_data_file` function
- `save_data` method
### Changed
- `data` parameter added to GenerativeImage `__init__`
- `data` parameter added to GenerativeImage `__init__` method
- `depth` parameter added to `save_image` method
- `depth` parameter added to `save_fig_file` function
- `save_image` and `nft_storage` methods background bug fixed
@ -136,7 +170,9 @@ 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.9...dev
[Unreleased]: https://github.com/sepandhaghighi/samila/compare/v1.1...dev
[1.1]: https://github.com/sepandhaghighi/samila/compare/v1.0...v1.1
[1.0]: https://github.com/sepandhaghighi/samila/compare/v0.9...v1.0
[0.9]: https://github.com/sepandhaghighi/samila/compare/v0.8...v0.9
[0.8]: https://github.com/sepandhaghighi/samila/compare/v0.7...v0.8
[0.7]: https://github.com/sepandhaghighi/samila/compare/v0.6...v0.7

Wyświetl plik

@ -25,7 +25,6 @@
* [Mathematical Details](https://github.com/sepandhaghighi/samila#mathematical-details)
* [Try Samila in Your Browser](https://github.com/sepandhaghighi/samila#try-samila-in-your-browser)
* [Issues & Bug Reports](https://github.com/sepandhaghighi/samila#issues--bug-reports)
* [Dependencies](https://github.com/sepandhaghighi/samila#dependencies)
* [Social Media](https://github.com/sepandhaghighi/samila#social-media)
* [Contribution](https://github.com/sepandhaghighi/samila/blob/master/.github/CONTRIBUTING.md)
* [References](https://github.com/sepandhaghighi/samila#references)
@ -39,7 +38,7 @@
## Overview
<p align="justify">
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.
Samila is a generative art generator written in Python, Samila lets you create images 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.
</p>
@ -89,7 +88,7 @@ Samila is a generative art generator written in Python, Samila let's you create
### Source code
- Download [Version 0.9](https://github.com/sepandhaghighi/samila/archive/v0.9.zip) or [Latest Source ](https://github.com/sepandhaghighi/samila/archive/dev.zip)
- Download [Version 1.1](https://github.com/sepandhaghighi/samila/archive/v1.1.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)
@ -97,7 +96,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.9` or `pip3 install samila==0.9` (Need root access)
- Run `pip install samila==1.1` or `pip3 install samila==1.1` (Need root access)
### Easy install
@ -156,6 +155,32 @@ Samila is a generative art generator written in Python, Samila let's you create
* Supported projections : `RECTILINEAR`, `POLAR`, `AITOFF`, `HAMMER`, `LAMBERT`, `MOLLWEIDE` and `RANDOM`
* Default projection is `RECTILINEAR`
### Marker
```pycon
>>> from samila import Marker
>>> g = GenerativeImage(f1, f2)
>>> g.generate()
>>> g.plot(marker=Marker.CIRCLE, spot_size=10)
>>> g.seed
448742
>>> plt.show()
```
<img src="https://github.com/sepandhaghighi/samila/raw/master/otherfiles/images/9.png">
* Supported markers : `POINT`, `PIXEL`, `CIRCLE`, `TRIANGLE_DOWN`, `TRIANGLE_UP`, `TRIANGLE_LEFT`, `TRIANGLE_RIGHT`, `TRI_DOWN`, `TRI_UP`, `TRI_LEFT`, `TRI_RIGHT`, `OCTAGON`, `SQUARE`, `PENTAGON`, `PLUS`, `PLUS_FILLED`, `STAR`, `HEXAGON_VERTICAL`, `HEXAGON_HORIZONTAL`, `X`, `X_FILLED`, `DIAMOND`, `DIAMON_THIN`, `VLINE`, `HLINE` and `RANDOM`
* Default marker is `POINT`
### Rotation
You can even rotate your art by using `rotation` parameter. Enter your desired rotation for the image in degrees and you will have it.
```pycon
>>> g = GenerativeImage(f1, f2)
>>> g.generate()
>>> g.plot(rotation=45)
```
* Default rotation is 0
### Range
```pycon
>>> g = GenerativeImage(f1, f2)
@ -228,10 +253,23 @@ You can make your custom color map and use it in Samila
Upload generated image directly to [NFT.storage](https://NFT.storage)
```pycon
>>> g.nft_storage(api_key="YOUR_API_KEY")
>>> g.nft_storage(api_key="YOUR_API_KEY", timeout=5000)
{'status': True, 'message': 'FILE_LINK'}
```
You can also upload your config/data to nft storage as follows:
```pycon
>>> g.nft_storage(api_key="API_KEY", upload_config=True)
{'status': {'image': True, 'config':True}, 'message': {'image':'IMAGE_FILE_LINK', 'config':'CONFIG_FILE_LINK'}
```
or
```pycon
>>> g.nft_storage(api_key="API_KEY", upload_data=True)
{'status': {'image': True, 'data':True}, 'message': {'image':'IMAGE_FILE_LINK', 'data':'DATA_FILE_LINK'}
```
* Default timeout is **3000** seconds
### Save image
Save generated image
@ -325,11 +363,11 @@ Samila is simply a transformation between a square-shaped space from the Cartesi
### 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:
We have set of points in the first space (left square) which can be defined as follow:
<img src="https://github.com/sepandhaghighi/samila/raw/master/otherfiles/mathematical_details/S1.jpg">
And bellow functions are used for transformation:
And below functions are used for transformation:
```pycon
>>> def f1(x, y):
@ -342,7 +380,7 @@ And bellow functions are used for transformation:
<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:
here we use `Projection.POLAR` so later space will be the polar space and we have:
```pycon
>>> g = GenerativeImage(f1, f2)
@ -375,19 +413,6 @@ You can also join our discord server
</a>
## Dependencies
<table>
<tr>
<td align="center">master</td>
<td align="center">dev</td>
</tr>
<tr>
<td align="center"><a href="https://requires.io/github/sepandhaghighi/samila/requirements/?branch=master"><img src="https://requires.io/github/sepandhaghighi/samila/requirements.svg?branch=master" alt="Requirements Status" /></a></td>
<td align="center"><a href="https://requires.io/github/sepandhaghighi/samila/requirements/?branch=dev"><img src="https://requires.io/github/sepandhaghighi/samila/requirements.svg?branch=dev" alt="Requirements Status" /></a></td>
</tr>
</table>
## Social media
1. [Instagram](https://www.instagram.com/samila_arts)

Wyświetl plik

@ -1,5 +1,5 @@
matplotlib==3.5.3
art==5.7
matplotlib==3.7.1
art==5.9
vulture>=1.0
bandit>=1.5.1
pydocstyle>=3.0.0

Wyświetl plik

@ -30,7 +30,7 @@
"import matplotlib.pyplot as plt\n",
"import random\n",
"import math\n",
"from samila import GenerativeImage, Projection"
"from samila import GenerativeImage, Projection, Marker"
]
},
{
@ -107,6 +107,53 @@
" plt.close()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Marker\n",
"We can use the `marker` attribute to change the plotting marker.\n",
"\n",
"The available markers are `POINT`, `PIXEL`, `CIRCLE`, `TRIANGLE_DOWN`, `TRIANGLE_UP`, `TRIANGLE_LEFT`, `TRIANGLE_RIGHT`, `TRI_DOWN`, `TRI_UP`, `TRI_LEFT`, `TRI_RIGHT`, `OCTAGON`, `SQUARE`, `PENTAGON`, `PLUS`, `PLUS_FILLED`, `STAR`, `HEXAGON_VERTICAL`, `HEXAGON_HORIZONTAL`, `X`, `X_FILLED`, `DIAMOND`, `DIAMON_THIN`, `VLINE`, `HLINE` and `RANDOM`."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"g2 = GenerativeImage(f1, f2)\n",
"g2.generate()\n",
"\n",
"for m in list(Marker):\n",
" print(m)\n",
" g2.plot(marker=m, spot_size=100)\n",
" plt.show()\n",
" plt.close()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Rotation\n",
"You can even rotate your art by using `rotation` parameter. Enter your desired rotation for the image in degrees and you will have it.\n",
"\n",
"* Default rotation is 0."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"g = GenerativeImage(f1, f2)\n",
"g.generate()\n",
"g.plot(rotation=45)"
]
},
{
"cell_type": "markdown",
"metadata": {},
@ -363,6 +410,47 @@
"source": [
"g1.nft_storage(api_key=\"YOUR_API_KEY\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"g1.nft_storage(api_key=\"YOUR_API_KEY\", timeout=5000)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can also upload your config/data to nft storage as follows:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"g1.nft_storage(api_key=\"YOUR_API_KEY\", upload_config=True)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"g1.nft_storage(api_key=\"YOUR_API_KEY\", upload_data=True)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* Default timeout is **3000** seconds"
]
}
],
"metadata": {

Plik binarny nie jest wyświetlany.

Po

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

Wyświetl plik

@ -1,5 +1,5 @@
{% set name = "samila" %}
{% set version = "0.9" %}
{% set version = "1.1" %}
package:
name: {{ name|lower }}

Wyświetl plik

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

Wyświetl plik

@ -1,3 +1,4 @@
matplotlib>=3.0.0
requests>=2.20.0
art>=1.8
Pillow>=6.2

Wyświetl plik

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
"""Samila modules."""
from .genimage import GenerativeImage
from .params import Projection, VALID_COLORS, SAMILA_VERSION
from .params import Projection, Marker, VALID_COLORS, SAMILA_VERSION
from .errors import samilaDataError, samilaGenerateError
__version__ = SAMILA_VERSION

Wyświetl plik

@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
"""Samila functions."""
import sys
import requests
import io
import os
@ -10,16 +11,19 @@ import random
import matplotlib
from matplotlib import cm
from matplotlib.colors import ListedColormap
from .params import DEFAULT_START, DEFAULT_STOP, DEFAULT_STEP, DEFAULT_COLOR, DEFAULT_IMAGE_SIZE, DEFAULT_DEPTH
from .params import DEFAULT_CMAP, DEFAULT_CMAP_RANGE
from PIL import Image
from .params import SAMILA_VERSION
from .params import DEFAULT_MARKER, DEFAULT_START, DEFAULT_STOP, DEFAULT_STEP, DEFAULT_COLOR, DEFAULT_IMAGE_SIZE, DEFAULT_DEPTH
from .params import DEFAULT_CMAP, DEFAULT_CMAP_RANGE, DEFAULT_ROTATION
from .params import DEFAULT_BACKGROUND_COLOR, DEFAULT_SPOT_SIZE, DEFAULT_PROJECTION, DEFAULT_ALPHA, DEFAULT_LINEWIDTH
from .params import Projection, VALID_COLORS, HEX_COLOR_PATTERN, NFT_STORAGE_API, NFT_STORAGE_LINK, OVERVIEW
from .params import Projection, Marker, VALID_COLORS, HEX_COLOR_PATTERN, NFT_STORAGE_API, NFT_STORAGE_LINK, OVERVIEW
from .params import DATA_TYPE_ERROR, DATA_FORMAT_ERROR, CONFIG_TYPE_ERROR, CONFIG_FORMAT_ERROR, PLOT_DATA_ERROR, CONFIG_NO_STR_FUNCTION_ERROR
from .params import NO_FIG_ERROR_MESSAGE, FIG_SAVE_SUCCESS_MESSAGE, NFT_STORAGE_SUCCESS_MESSAGE, SAVE_NO_DATA_ERROR
from .params import INVALID_COLOR_TYPE_ERROR, COLOR_SIZE_ERROR
from .params import BOTH_COLOR_COMPLEMENT_WARNING, COLOR_NOT_FOUND_WARNING
from .params import DATA_SAVE_SUCCESS_MESSAGE, SEED_LOWER_BOUND, SEED_UPPER_BOUND
from .params import ELEMENTS_LIST, ARGUMENTS_LIST, OPERATORS_LIST, RANDOM_COEF_LIST
from .params import RANDOM_EQUATION_MIN_COMPLEXITY, RANDOM_EQUATION_MAX_COMPLEXITY, RANDOM_EQUATION_FOF_MIN_DEPTH, RANDOM_EQUATION_FOF_MAX_DEPTH
from .errors import samilaDataError, samilaPlotError, samilaConfigError
from warnings import warn
@ -30,17 +34,20 @@ def random_equation_gen():
:return: equation as str
"""
num_elements = random.randint(1, len(ELEMENTS_LIST))
num_elements = random.randint(
RANDOM_EQUATION_MIN_COMPLEXITY,
RANDOM_EQUATION_MAX_COMPLEXITY)
result = ""
index = 1
random_coef = random.choice(RANDOM_COEF_LIST)
while(index <= num_elements):
argument = random.choice(ARGUMENTS_LIST)
if random.randint(0, 1) == 1:
argument = random.choice(ELEMENTS_LIST).format(
random_coef, argument)
result = result + \
random.choice(ELEMENTS_LIST).format(random_coef, argument)
element = random.choice(ARGUMENTS_LIST)
fof_depth = random.randint(
RANDOM_EQUATION_FOF_MIN_DEPTH,
RANDOM_EQUATION_FOF_MAX_DEPTH)
for _ in range(fof_depth):
element = random.choice(ELEMENTS_LIST).format(random_coef, element)
result = result + element
if index < num_elements:
result = result + random.choice(OPERATORS_LIST)
index = index + 1
@ -257,6 +264,24 @@ def filter_projection(projection):
return None
def filter_marker(marker):
"""
Filter given marker.
:param marker: given marker
:type marker: Marker enum
:return: filtered version of marker
"""
if isinstance(marker, Marker):
marker_value = marker.value
if marker_value == "random":
marker_list = list(Marker)
marker_list.remove(Marker.RANDOM)
marker_value = random.choice(marker_list).value
return marker_value
return None
def filter_float(value):
"""
Filter given float value.
@ -284,6 +309,30 @@ def filter_size(size):
return None
def rotate(fig, ax, rotation):
"""
Rotate the given figure and return axis.
:param fig: figure containing the image
:type fig: Figure
:param ax: axis on which rotated image is ploted
:type ax: Axis
:param rotation: desired rotation (in degrees)
:type rotation: float
:return: axis containing rotated image
"""
if rotation != DEFAULT_ROTATION:
buf = io.BytesIO()
fig.savefig(buf, format='png')
ax.cla()
with Image.open(buf) as im:
ax.imshow(im.rotate(rotation))
ax.set_axis_off()
ax.patch.set_zorder(-1)
ax.add_artist(ax.patch)
return ax
def plot_params_filter(
g,
color=None,
@ -292,8 +341,10 @@ def plot_params_filter(
spot_size=None,
size=None,
projection=None,
marker=None,
alpha=None,
linewidth=None):
linewidth=None,
rotation=None):
"""
Filter plot method parameters.
@ -311,10 +362,14 @@ def plot_params_filter(
:type size: tuple
:param projection: projection type
:type projection: str
:param marker: marker type
:type marker: str
:param alpha: point transparency
:type alpha: float
:param linewidth: width of line
:type linewidth: float
:param rotation: desired rotation (in degrees)
:type rotation: float
:return: None
"""
if g.data1 is None:
@ -329,6 +384,7 @@ def plot_params_filter(
color, bgcolor = filter_color(color, bgcolor)
cmap = filter_cmap(cmap)
projection = filter_projection(projection)
marker = filter_marker(marker)
alpha = filter_float(alpha)
linewidth = filter_float(linewidth)
spot_size = filter_float(spot_size)
@ -345,12 +401,16 @@ def plot_params_filter(
size = g.size
if projection is None:
projection = g.projection
if marker is None:
marker = g.marker
if alpha is None:
alpha = g.alpha
if linewidth is None:
linewidth = g.linewidth
g.color, g.bgcolor, g.cmap, g.spot_size, g.size, g.projection, g.alpha, g.linewidth = \
color, bgcolor, cmap, spot_size, size, projection, alpha, linewidth
if rotation is None:
rotation = g.rotation
g.color, g.bgcolor, g.cmap, g.spot_size, g.size, g.projection, g.marker, g.alpha, g.linewidth, g.rotation = \
color, bgcolor, cmap, spot_size, size, projection, marker, alpha, linewidth, rotation
def generate_params_filter(
@ -388,27 +448,6 @@ def generate_params_filter(
g.seed, g.start, g.step, g.stop = seed, start, step, stop
def fill_data(g, point):
"""
Fill data with functions in given points.
:param g: generative image instance
:type g: GenerativeImage
:param point: given point
:type point: tuple
:return: false if some exception occurred
"""
random.seed(g.seed)
try:
data1_ = g.function1(point[0], point[1]).real
data2_ = g.function2(point[0], point[1]).real
except Exception:
return False
g.data1.append(data1_)
g.data2.append(data2_)
return True
def save_params_filter(g, depth=None):
"""
Filter save_image method parameters.
@ -434,7 +473,9 @@ def _GI_initializer(g, function1, function2):
:type function2: python or lambda function
:return: None
"""
g.__version__ = SAMILA_VERSION
g.matplotlib_version = matplotlib.__version__
g.python_version = get_python_version()
g.function1 = function1
g.function1_str = None
g.function2 = function2
@ -452,12 +493,15 @@ def _GI_initializer(g, function1, function2):
g.spot_size = DEFAULT_SPOT_SIZE
g.size = DEFAULT_IMAGE_SIZE
g.projection = DEFAULT_PROJECTION
g.marker = DEFAULT_MARKER
g.alpha = DEFAULT_ALPHA
g.linewidth = DEFAULT_LINEWIDTH
g.rotation = DEFAULT_ROTATION
g.depth = DEFAULT_DEPTH
g.missed_points_number = 0
def nft_storage_upload(api_key, data):
def nft_storage_upload(api_key, data, timeout):
"""
Upload file to nft.storage.
@ -465,6 +509,8 @@ def nft_storage_upload(api_key, data):
:type api_key: str
:param data: image data
:type data: binary
:param timeout: upload timeout (in seconds)
:type timeout: int
:return: result as dict
"""
result = {"status": True, "message": NFT_STORAGE_SUCCESS_MESSAGE}
@ -473,7 +519,8 @@ def nft_storage_upload(api_key, data):
response = requests.post(
url=NFT_STORAGE_API,
data=data,
headers=headers)
headers=headers,
timeout=timeout)
response_json = response.json()
if response_json["ok"]:
result["message"] = NFT_STORAGE_LINK.format(
@ -498,7 +545,38 @@ def save_data_file(g, file_adr):
:type file_adr: str
:return: result as dict
"""
matplotlib_version = matplotlib.__version__
data = get_data(g)
result = {"status": True, "message": DATA_SAVE_SUCCESS_MESSAGE}
try:
with open(file_adr, 'w') as fp:
json.dump(data, fp)
result["message"] = os.path.abspath(file_adr)
except Exception as e:
result["status"] = False
result["message"] = str(e)
return result
def get_python_version():
"""
Get Python's version.
:return: python's version as 'major.minor'
"""
return "{}.{}".format(
sys.version_info.major,
sys.version_info.minor
)
def get_data(g):
"""
Return data.
:param g: generative image instance
:type g: GenerativeImage
:return: data as a dict
"""
data = {}
if g.data1 is None or g.data2 is None:
raise samilaDataError(SAVE_NO_DATA_ERROR)
@ -510,20 +588,53 @@ def save_data_file(g, file_adr):
"cmap": _serialize_cmap(g.cmap),
"spot_size": g.spot_size,
"projection": g.projection,
"marker": g.marker,
"alpha": g.alpha,
"linewidth": g.linewidth,
"depth": g.depth
"depth": g.depth,
"rotation": g.rotation,
}
data['matplotlib_version'] = matplotlib_version
result = {"status": True, "message": DATA_SAVE_SUCCESS_MESSAGE}
try:
with open(file_adr, 'w') as fp:
json.dump(data, fp)
result["message"] = os.path.abspath(file_adr)
except Exception as e:
result["status"] = False
result["message"] = str(e)
return result
data['matplotlib_version'] = g.matplotlib_version
data['python_version'] = g.python_version
data['__version__'] = g.__version__
return data
def get_config(g):
"""
Return config.
:param g: generative image instance
:type g: GenerativeImage
:return: config as a dict
"""
config = {}
if g.function1_str is None or g.function2_str is None:
raise samilaConfigError(CONFIG_NO_STR_FUNCTION_ERROR)
config['f1'] = g.function1_str
config['f2'] = g.function2_str
config['generate'] = {
"seed": g.seed,
"start": g.start,
"step": g.step,
"stop": g.stop
}
config['plot'] = {
"color": g.color,
"bgcolor": g.bgcolor,
"cmap": _serialize_cmap(g.cmap),
"spot_size": g.spot_size,
"projection": g.projection,
"marker": g.marker,
"alpha": g.alpha,
"linewidth": g.linewidth,
"depth": g.depth,
"rotation": g.rotation,
}
config['matplotlib_version'] = g.matplotlib_version
config['python_version'] = g.python_version
config['__version__'] = g.__version__
return config
def save_config_file(g, file_adr):
@ -536,33 +647,11 @@ def save_config_file(g, file_adr):
:type file_adr: str
:return: result as dict
"""
matplotlib_version = matplotlib.__version__
data = {}
if g.function1_str is None or g.function2_str is None:
raise samilaConfigError(CONFIG_NO_STR_FUNCTION_ERROR)
data['f1'] = g.function1_str
data['f2'] = g.function2_str
data['generate'] = {
"seed": g.seed,
"start": g.start,
"step": g.step,
"stop": g.stop
}
data['plot'] = {
"color": g.color,
"bgcolor": g.bgcolor,
"cmap": _serialize_cmap(g.cmap),
"spot_size": g.spot_size,
"projection": g.projection,
"alpha": g.alpha,
"linewidth": g.linewidth,
"depth": g.depth
}
data['matplotlib_version'] = matplotlib_version
config = get_config(g)
result = {"status": True, "message": DATA_SAVE_SUCCESS_MESSAGE}
try:
with open(file_adr, 'w') as fp:
json.dump(data, fp, indent=4)
json.dump(config, fp, indent=4)
result["message"] = os.path.abspath(file_adr)
except Exception as e:
result["status"] = False
@ -716,6 +805,10 @@ def load_data(g, data):
raise samilaDataError(DATA_FORMAT_ERROR)
if 'matplotlib_version' in data:
g.matplotlib_version = data['matplotlib_version']
if 'python_version' in data:
g.python_version = data['python_version']
if '__version__' in data:
g.__version__ = data['__version__']
plot_config = data.get("plot")
if plot_config is not None:
g.color = plot_config.get("color", DEFAULT_COLOR)
@ -723,9 +816,11 @@ def load_data(g, data):
g.cmap = _load_cmap(plot_config)
g.spot_size = plot_config.get("spot_size", DEFAULT_SPOT_SIZE)
g.projection = plot_config.get("projection", DEFAULT_PROJECTION)
g.marker = plot_config.get("marker", DEFAULT_MARKER)
g.alpha = plot_config.get("alpha", DEFAULT_ALPHA)
g.linewidth = plot_config.get("linewidth", DEFAULT_LINEWIDTH)
g.depth = plot_config.get("depth", DEFAULT_DEPTH)
g.rotation = plot_config.get("rotation", DEFAULT_ROTATION)
return
raise samilaDataError(DATA_TYPE_ERROR)
@ -741,28 +836,34 @@ def load_config(g, config):
:return: None
"""
if isinstance(config, io.IOBase):
data = json.load(config)
g.function1_str = data.get("f1")
g.function2_str = data.get("f2")
config = json.load(config)
g.function1_str = config.get("f1")
g.function2_str = config.get("f2")
if g.function1_str is None or g.function2_str is None:
raise samilaConfigError(CONFIG_FORMAT_ERROR)
if 'matplotlib_version' in data:
g.matplotlib_version = data['matplotlib_version']
generate_config = data.get("generate")
if 'matplotlib_version' in config:
g.matplotlib_version = config['matplotlib_version']
if 'python_version' in config:
g.python_version = config['python_version']
if '__version__' in config:
g.__version__ = config['__version__']
generate_config = config.get("generate")
if generate_config is not None:
g.seed = generate_config.get("seed")
g.start = generate_config.get("start", DEFAULT_START)
g.step = generate_config.get("step", DEFAULT_STEP)
g.stop = generate_config.get("stop", DEFAULT_STOP)
plot_config = data.get("plot")
plot_config = config.get("plot")
if plot_config is not None:
g.color = plot_config.get("color", DEFAULT_COLOR)
g.bgcolor = plot_config.get("bgcolor", DEFAULT_BACKGROUND_COLOR)
g.cmap = _load_cmap(plot_config)
g.spot_size = plot_config.get("spot_size", DEFAULT_SPOT_SIZE)
g.projection = plot_config.get("projection", DEFAULT_PROJECTION)
g.marker = plot_config.get("marker", DEFAULT_MARKER)
g.alpha = plot_config.get("alpha", DEFAULT_ALPHA)
g.linewidth = plot_config.get("linewidth", DEFAULT_LINEWIDTH)
g.depth = plot_config.get("depth", DEFAULT_DEPTH)
g.rotation = plot_config.get("rotation", DEFAULT_ROTATION)
return
raise samilaConfigError(CONFIG_TYPE_ERROR)

Wyświetl plik

@ -1,16 +1,18 @@
# -*- coding: utf-8 -*-
"""Samila generative image."""
import json
import random
import gc
import itertools
import matplotlib
import matplotlib.pyplot as plt
from .functions import _GI_initializer, plot_params_filter, generate_params_filter, save_params_filter
from .functions import get_config, get_data, get_python_version
from .functions import float_range, save_data_file, save_fig_file, save_fig_buf, save_config_file
from .functions import load_data, load_config, random_equation_gen, nft_storage_upload, fill_data
from .functions import set_background
from .functions import load_data, load_config, random_equation_gen, nft_storage_upload
from .functions import set_background, rotate
from .params import *
from warnings import warn
from warnings import warn, catch_warnings, simplefilter
class GenerativeImage:
@ -42,10 +44,14 @@ class GenerativeImage:
load_config(self, config)
elif data is not None:
load_data(self, data)
if self.matplotlib_version != matplotlib.__version__:
if self.matplotlib_version != matplotlib.__version__ or \
self.python_version != get_python_version() or \
self.__version__ != SAMILA_VERSION:
warn(
MATPLOTLIB_VERSION_WARNING.format(
self.matplotlib_version),
VERSION_WARNING.format(
self.matplotlib_version,
self.python_version,
self.__version__),
RuntimeWarning)
if self.function1 is None:
if self.function1_str is None:
@ -78,13 +84,19 @@ class GenerativeImage:
generate_params_filter(self, seed, start, step, stop)
self.data1 = []
self.data2 = []
self.missed_points_number = 0
range1 = list(float_range(self.start, self.stop, self.step))
range_prod = list(itertools.product(range1, range1))
calc_exception = False
range_prod = itertools.product(range1, range1)
for point in range_prod:
if not fill_data(self, point):
calc_exception = True
if calc_exception:
random.seed(self.seed)
try:
data1_ = self.function1(point[0], point[1]).real
data2_ = self.function2(point[0], point[1]).real
self.data1.append(data1_)
self.data2.append(data2_)
except Exception:
self.missed_points_number += 1
if len(self.data1) < (len(range1) ** 2):
warn(CALCULATION_EXCEPTION_WARNING, RuntimeWarning)
def plot(
@ -95,8 +107,10 @@ class GenerativeImage:
spot_size=None,
size=None,
projection=None,
marker=None,
alpha=None,
linewidth=None):
linewidth=None,
rotation=None):
"""
Plot the generated art.
@ -112,10 +126,14 @@ class GenerativeImage:
:type size: tuple
:param projection: projection type
:type projection: str
:param marker: marker type
:type marker: str
:param alpha: point transparency
:type alpha: float
:param linewidth: width of line
:type linewidth: float
:param rotation: desired rotation (in degrees)
:type rotation: float
:return: None
"""
plot_params_filter(
@ -126,33 +144,51 @@ class GenerativeImage:
spot_size,
size,
projection,
marker,
alpha,
linewidth)
linewidth,
rotation)
fig = plt.figure()
fig.set_size_inches(self.size[0], self.size[1])
ax = fig.add_subplot(111, projection=self.projection)
set_background(self.bgcolor, fig, ax)
ax.scatter(
self.data2,
self.data1,
alpha=self.alpha,
c=self.color,
cmap=self.cmap,
s=self.spot_size,
lw=self.linewidth)
with catch_warnings():
simplefilter("ignore")
ax.scatter(
self.data2,
self.data1,
alpha=self.alpha,
c=self.color,
cmap=self.cmap,
s=self.spot_size,
lw=self.linewidth,
marker=self.marker)
ax.set_axis_off()
ax.patch.set_zorder(-1)
ax.add_artist(ax.patch)
ax = rotate(fig, ax, self.rotation)
self.fig = fig
def nft_storage(self, api_key, depth=None):
def nft_storage(
self,
api_key,
upload_data=False,
upload_config=False,
depth=None,
timeout=3000):
"""
Upload image to nft.storage.
:param api_key: API key
:type api_key: str
:param upload_data: upload data flag
:type upload_data: bool
:param upload_config: upload config flag
:type upload_config: bool
:param depth: image depth
:type depth: float
:param timeout: upload timeout (in seconds)
:type timeout: int
:return: result as dict
"""
save_params_filter(self, depth)
@ -160,8 +196,28 @@ class GenerativeImage:
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
response = nft_storage_upload(
api_key=api_key,
data=buf.getvalue(),
timeout=timeout)
if upload_config == False and upload_data == False:
return response
result = {key: {'image': value} for key, value in response.items()}
if upload_config:
response = nft_storage_upload(
api_key=api_key,
data=json.dumps(get_config(self)),
timeout=timeout)
for key, value in response.items():
result[key]['config'] = value
if upload_data:
response = nft_storage_upload(
api_key=api_key,
data=json.dumps(get_data(self)),
timeout=timeout)
for key, value in response.items():
result[key]['data'] = value
return result
def save_image(self, file_adr, depth=None):
"""

Wyświetl plik

@ -5,7 +5,7 @@ from enum import Enum
from matplotlib import colors as mcolors
from matplotlib import cm
SAMILA_VERSION = "0.9" # pragma: no cover
SAMILA_VERSION = "1.1" # pragma: no cover
OVERVIEW = '''
Samila is a generative art generator written in Python, Samila let's you
@ -26,7 +26,9 @@ DEFAULT_LINEWIDTH = 1.5
DEFAULT_IMAGE_SIZE = (10, 10)
DEFAULT_SPOT_SIZE = 0.01
DEFAULT_DEPTH = 1
DEFAULT_ROTATION = 0.0
DEFAULT_PROJECTION = "rectilinear"
DEFAULT_MARKER = "."
SEED_LOWER_BOUND = 0
SEED_UPPER_BOUND = 2**20
VALID_COLORS = list(dict(mcolors.BASE_COLORS, **mcolors.CSS4_COLORS).keys())
@ -46,7 +48,7 @@ PLOT_DATA_ERROR = "Plotting process can't be Done because data{0} is empty. Use
COLOR_SIZE_ERROR = "Color list size is not equal to the data size."
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."
MATPLOTLIB_VERSION_WARNING = "Source matplotlib version({0}) is different from yours, plots may be different."
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}'"
@ -69,6 +71,42 @@ class Projection(Enum):
RANDOM = "random"
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)",
@ -77,6 +115,7 @@ RANDOM_COEF_LIST = [
"random.lognormvariate(0,1)"]
ELEMENTS_LIST = [
"{0}*math.exp({1})",
"{0}*math.atan({1})",
"{0}*math.asinh({1})",
"{0}*math.acosh(abs({1})+1)",
@ -86,7 +125,9 @@ ELEMENTS_LIST = [
"{0}*math.tanh({1})",
"{0}*math.cos({1})",
"{0}*math.sin({1})",
"{0}*math.tan({1})",
"{0}*{1}",
"{0}/{1}",
"{0}*abs({1})",
"{0}*math.ceil({1})",
"{0}*math.floor({1})"]
@ -95,6 +136,9 @@ ARGUMENTS_LIST = [
"x*y",
"x",
"y",
"1/x",
"1/y",
"x/y",
"y-x",
"x-y",
"x+y",
@ -112,3 +156,11 @@ ARGUMENTS_LIST = [
"y*(x**3)"]
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

Wyświetl plik

@ -6,7 +6,8 @@ except ImportError:
from distutils.core import setup
MINIMAL_DESCRIPTION = '''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.'''
MINIMAL_DESCRIPTION = '''Samila is a generative art generator written in Python, Samila lets you create images 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.'''
def get_requires():
@ -32,14 +33,14 @@ def read_description():
setup(
name='samila',
packages=['samila'],
version='0.9',
version='1.1',
description='Generative ART',
long_description=read_description(),
long_description_content_type='text/markdown',
author='Samila Development Team',
author_email='info@samila.site',
url='https://www.samila.site',
download_url='https://github.com/sepandhaghighi/samila/tarball/v0.9',
download_url='https://github.com/sepandhaghighi/samila/tarball/v1.1',
keywords="generative-art art nft file nft-storage",
project_urls={
'Source': 'https://github.com/sepandhaghighi/samila',
@ -49,7 +50,7 @@ setup(
install_requires=get_requires(),
python_requires='>=3.5',
classifiers=[
'Development Status :: 4 - Beta',
'Development Status :: 5 - Production/Stable',
'Natural Language :: English',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
@ -67,6 +68,7 @@ setup(
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
],
license='MIT',
include_package_data=True

Wyświetl plik

@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
"""
>>> import random
>>> import sys
>>> from samila.functions import *
>>> is_valid_color("blue")
True
@ -75,12 +76,23 @@ False
>>> projection2 = filter_projection(Projection.RANDOM)
>>> projection1 == projection2
False
>>> filter_marker(3)
>>> filter_marker(Marker.POINT)
'.'
>>> random.seed(2)
>>> marker1 = filter_marker(Marker.RANDOM)
>>> random.seed(3)
>>> marker2 = filter_marker(Marker.RANDOM)
>>> marker1 == marker2
False
>>> distance_calc("test","test1")
1
>>> distance_calc("te1st","test")
1
>>> distance_calc("test12","test234")
3
>>> get_python_version() == '.'.join(sys.version.split()[0].split('.')[:2])
True
>>> samila_help()
<BLANKLINE>
Samila is a generative art generator written in Python, Samila let's you

Wyświetl plik

@ -20,4 +20,26 @@
... time.sleep(10)
>>> status
True
>>> status = False
>>> counter = 0
>>> while(status == False and counter<try_limit):
... result = g.nft_storage(api_key=NFT_STORAGE_API_KEY, upload_config=True)
... counter = counter + 1
... status = all(result["status"].values())
... time.sleep(10)
>>> result['status']["image"]
True
>>> result['status']["config"]
True
>>> status = False
>>> counter = 0
>>> while(status == False and counter<try_limit):
... result = g.nft_storage(api_key=NFT_STORAGE_API_KEY, upload_data=True)
... counter = counter + 1
... status = all(result["status"].values())
... time.sleep(10)
>>> result['status']["image"]
True
>>> result['status']["data"]
True
"""

Wyświetl plik

@ -6,10 +6,11 @@
>>> import pickle
>>> import socket
>>> import json
>>> import sys
>>> from matplotlib.colors import Colormap, ListedColormap
>>> def guard(*args, **kwargs):
... raise Exception("No internet connection!")
>>> from samila import GenerativeImage, Projection
>>> from samila import GenerativeImage, Projection, Marker
>>> from samila.functions import is_same_data
>>> import pickle
>>> def f1(x,y):
@ -23,12 +24,16 @@
True
>>> g.function2 == f2
True
>>> g.python_version == '.'.join(sys.version.split()[0].split('.')[:2])
True
>>> g.fig
>>> g.generate()
>>> isinstance(g.data1, list)
True
>>> isinstance(g.data2, list)
True
>>> g.missed_points_number == 0
True
>>> g.generate(seed=10, start=-2*math.pi, step=0.1, stop=math.pi/2)
>>> g.seed
10
@ -53,7 +58,6 @@ True
True
>>> isinstance(result["message"], str)
True
>>> from samila import GenerativeImage, Projection
>>> g.plot(projection=Projection.POLAR, color='red', bgcolor='black')
>>> g.color
'red'
@ -84,11 +88,18 @@ True
'#555555'
>>> g.bgcolor
'#aaaaaa'
>>> g.plot(projection=Projection.POLAR, color="complement", bgcolor="complement")
>>> g.plot(projection=Projection.POLAR, color="complement", bgcolor="complement", marker=Marker.X, spot_size=100)
>>> g.color
'#555555'
>>> g.bgcolor
'#aaaaaa'
>>> g.marker
'x'
>>> g.spot_size
100
>>> g.plot(rotation=45)
>>> int(g.rotation)
45
>>> g.plot(bgcolor=(.1, .2, .8), spot_size=0.1)
>>> g.plot(size=(20, 20))
>>> g.size
@ -99,17 +110,19 @@ True
>>> g.linewidth
2.2
>>> random.seed(2)
>>> g.plot(color="random", bgcolor="random", projection=Projection.RANDOM)
>>> color1, bgcolor1, projection1 = g.color, g.bgcolor, g.projection
>>> g.plot(color="random", bgcolor="random", projection=Projection.RANDOM, marker=Marker.RANDOM)
>>> color1, bgcolor1, projection1, marker1 = g.color, g.bgcolor, g.projection, g.marker
>>> random.seed(3)
>>> g.plot(color="random", bgcolor="random", projection=Projection.RANDOM)
>>> color2, bgcolor2, projection2 = g.color, g.bgcolor, g.projection
>>> g.plot(color="random", bgcolor="random", projection=Projection.RANDOM, marker=Marker.RANDOM)
>>> color2, bgcolor2, projection2, marker2 = g.color, g.bgcolor, g.projection, g.marker
>>> color1 == color2
False
>>> bgcolor1 == bgcolor2
False
>>> projection1 == projection2
False
>>> marker1 == marker2
False
>>> result = g.nft_storage(api_key="")
>>> result['status']
False
@ -165,7 +178,7 @@ True
>>> g.plot(color="white", bgcolor="transparent")
>>> g.bgcolor == "TRANSPARENT"
True
>>> g.plot(color="white", bgcolor="black", spot_size=0.1)
>>> g.plot()
>>> result = g.save_config()
>>> result["status"]
True
@ -189,6 +202,16 @@ True
True
>>> g.spot_size == g_.spot_size
True
>>> g.projection == g_.projection
True
>>> g.marker == g_.marker
True
>>> g.alpha == g_.alpha
True
>>> g.linewidth == g_.linewidth
True
>>> g.depth == g_.depth
True
>>> g_ = GenerativeImage(data=open("data.json", 'r'))
>>> g.color == g_.color
True
@ -196,6 +219,71 @@ True
True
>>> g.spot_size == g_.spot_size
True
>>> g.projection == g_.projection
True
>>> g.marker == g_.marker
True
>>> g.rotation == g_.rotation
True
>>> g.alpha == g_.alpha
True
>>> g.linewidth == g_.linewidth
True
>>> g.depth == g_.depth
True
>>> g.plot(color="white", bgcolor="black", spot_size=2, projection=Projection.POLAR, marker=Marker.X, alpha=0.2, linewidth=1)
>>> result = g.save_config()
>>> result["status"]
True
>>> isinstance(result["message"], str)
True
>>> result = g.save_data()
>>> result["status"]
True
>>> isinstance(result["message"], str)
True
>>> g_ = GenerativeImage(config=open("config.json", 'r'))
>>> g_.seed == g.seed
True
>>> g_.function1_str == g.function1_str
True
>>> g_.function2_str == g.function2_str
True
>>> g.color == g_.color
True
>>> g.bgcolor == g_.bgcolor
True
>>> g.spot_size == g_.spot_size
True
>>> g.projection == g_.projection
True
>>> g.marker == g_.marker
True
>>> g.rotation == g_.rotation
True
>>> g.alpha == g_.alpha
True
>>> g.linewidth == g_.linewidth
True
>>> g.depth == g_.depth
True
>>> g_ = GenerativeImage(data=open("data.json", 'r'))
>>> g.color == g_.color
True
>>> g.bgcolor == g_.bgcolor
True
>>> g.spot_size == g_.spot_size
True
>>> g.projection == g_.projection
True
>>> g.marker == g_.marker
True
>>> g.alpha == g_.alpha
True
>>> g.linewidth == g_.linewidth
True
>>> g.depth == g_.depth
True
>>> with open("config.json", 'w') as fp:
... json.dump({'f1': 'y', 'f2': 'x'}, fp)
>>> g = GenerativeImage(config=open("config.json", 'r'))

Wyświetl plik

@ -13,16 +13,34 @@ True
>>> g_.data2 == g.data2
True
>>> with open('data.json', 'w') as fp:
... json.dump({'data1': [0], 'data2': [0], '__version__': '0'}, fp)
>>> with warns(RuntimeWarning, match=r"Your plots may differ as the version of matplotlib (.*), Python (.*), or Samila (.*) that you are using is not the same as the source."):
... g = GenerativeImage(data=open('data.json', 'r'))
>>> with open('config.json', 'w') as fp:
... json.dump({'f1': 'x', 'f2': 'y', '__version__': '0'}, fp)
>>> with warns(RuntimeWarning, match=r"Your plots may differ as the version of matplotlib (.*), Python (.*), or Samila (.*) that you are using is not the same as the source."):
... g = GenerativeImage(config=open('config.json', 'r'))
>>> with open('data.json', 'w') as fp:
... json.dump({'data1': [0], 'data2': [0], 'python_version': '0'}, fp)
>>> with warns(RuntimeWarning, match=r"Your plots may differ as the version of matplotlib (.*), Python (.*), or Samila (.*) that you are using is not the same as the source."):
... g = GenerativeImage(data=open('data.json', 'r'))
>>> with open('config.json', 'w') as fp:
... json.dump({'f1': 'x', 'f2': 'y', 'python_version': '0'}, fp)
>>> with warns(RuntimeWarning, match=r"Your plots may differ as the version of matplotlib (.*), Python (.*), or Samila (.*) that you are using is not the same as the source."):
... g = GenerativeImage(config=open('config.json', 'r'))
>>> with open('data.json', 'w') as fp:
... json.dump({'data1': [0], 'data2': [0], 'matplotlib_version': '0'}, fp)
>>> with warns(RuntimeWarning, match=r"Source matplotlib version(.*) is different from yours, plots may be different."):
... g = GenerativeImage(lambda x,y: 0, lambda x,y: 0, data=open('data.json', 'r'))
>>> with warns(RuntimeWarning, match=r"Your plots may differ as the version of matplotlib (.*), Python (.*), or Samila (.*) that you are using is not the same as the source."):
... g = GenerativeImage(data=open('data.json', 'r'))
>>> with open('config.json', 'w') as fp:
... json.dump({'f1': 'x', 'f2': 'y', 'matplotlib_version': '0'}, fp)
>>> with warns(RuntimeWarning, match=r"Source matplotlib version(.*) is different from yours, plots may be different."):
>>> with warns(RuntimeWarning, match=r"Your plots may differ as the version of matplotlib (.*), Python (.*), or Samila (.*) that you are using is not the same as the source."):
... g = GenerativeImage(config=open('config.json', 'r'))
>>> g = GenerativeImage(lambda x, y: 1 / x, lambda x, y: 1 / (y - 1))
>>> with warns(RuntimeWarning, match=r"The given functions are undefined at some points. Your plot may not be complete."):
... g.generate(start=0, stop=2, step=0.1)
>>> g.missed_points_number > 0
True
>>> with warns(RuntimeWarning, match=r"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."):
... g.plot(color='complement', bgcolor='complement')
>>> with warns(RuntimeWarning, match=r"color 'rad' not found. Replacing it with 'red'"):