samila/README.md

384 wiersze
12 KiB
Markdown
Czysty Zwykły widok Historia

2021-09-29 09:18:45 +00:00
<div align="center">
<img src="https://github.com/sepandhaghighi/samila/raw/master/otherfiles/logo.png" width=400 height=400>
2021-09-29 09:18:45 +00:00
<br/>
<h1>Samila</h1>
2021-09-29 09:18:45 +00:00
<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">
<img src="https://codecov.io/gh/sepandhaghighi/samila/branch/master/graph/badge.svg" />
</a>
<a href="https://badge.fury.io/py/samila"><img src="https://badge.fury.io/py/samila.svg" alt="PyPI version" height="18"></a>
2021-10-30 08:20:21 +00:00
<a href="https://discord.com/invite/94bz5QGZWb">
2021-10-30 08:31:24 +00:00
<img src="https://img.shields.io/discord/900055829225562162.svg" alt="Discord Channel">
2021-10-30 07:02:11 +00:00
</a>
2021-09-29 09:18:45 +00:00
</div>
----------
## Table of contents
* [Overview](https://github.com/sepandhaghighi/samila#overview)
* [Installation](https://github.com/sepandhaghighi/samila#installation)
* [Usage](https://github.com/sepandhaghighi/samila#usage)
2021-10-10 21:36:29 +00:00
* [Mathematical Details](https://github.com/sepandhaghighi/samila#mathematical-details)
2021-09-29 09:18:45 +00:00
* [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)
* [References](https://github.com/sepandhaghighi/samila#references)
* [Authors](https://github.com/sepandhaghighi/samila/blob/master/AUTHORS.md)
* [License](https://github.com/sepandhaghighi/samila/blob/master/LICENSE)
* [Show Your Support](https://github.com/sepandhaghighi/samila#show-your-support)
* [Changelog](https://github.com/sepandhaghighi/samila/blob/master/CHANGELOG.md)
* [Code of Conduct](https://github.com/sepandhaghighi/samila/blob/master/.github/CODE_OF_CONDUCT.md)
## 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.
</p>
<table>
<tr>
<td align="center">Open Hub</td>
<td align="center"><a href="https://www.openhub.net/p/samila"><img src="https://www.openhub.net/p/samila/widgets/project_thin_badge.gif"></a></td>
</tr>
<tr>
<td align="center">PyPI Counter</td>
2021-10-11 06:32:57 +00:00
<td align="center"><a href="http://pepy.tech/project/samila"><img src="http://pepy.tech/badge/samila"></a></td>
2021-09-29 09:18:45 +00:00
</tr>
<tr>
<td align="center">Github Stars</td>
<td align="center"><a href="https://github.com/sepandhaghighi/samila"><img src="https://img.shields.io/github/stars/sepandhaghighi/samila.svg?style=social&label=Stars"></a></td>
</tr>
</table>
<table>
<tr>
<td align="center">Branch</td>
<td align="center">master</td>
<td align="center">dev</td>
</tr>
<tr>
<td align="center">CI</td>
<td align="center"><img src="https://github.com/sepandhaghighi/samila/workflows/CI/badge.svg?branch=master"></td>
<td align="center"><img src="https://github.com/sepandhaghighi/samila/workflows/CI/badge.svg?branch=dev"></td>
</tr>
</table>
<table>
<tr>
<td align="center">Code Quality</td>
2021-09-30 12:14:53 +00:00
<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>
2021-09-29 09:18:45 +00:00
</tr>
</table>
## Installation
### Source code
2022-01-08 12:16:12 +00:00
- Download [Version 0.4](https://github.com/sepandhaghighi/samila/archive/v0.4.zip) or [Latest Source ](https://github.com/sepandhaghighi/samila/archive/dev.zip)
2021-09-29 09:18:45 +00:00
- 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)
### PyPI
- Check [Python Packaging User Guide](https://packaging.python.org/installing/)
2022-01-08 12:16:12 +00:00
- Run `pip install samila==0.4` or `pip3 install samila==0.4` (Need root access)
2021-09-29 09:18:45 +00:00
### Easy install
- Run `easy_install --upgrade samila` (Need root access)
## Usage
2021-12-18 19:43:26 +00:00
### Magic
```pycon
>>> import matplotlib.pyplot as plt
>>> from samila import GenerativeImage
>>> g = GenerativeImage()
>>> g.generate()
>>> g.plot()
>>> plt.show()
```
<img src="https://github.com/sepandhaghighi/samila/raw/master/otherfiles/images/7.png">
2021-09-29 09:18:45 +00:00
### Basic
```pycon
2021-09-29 10:04:04 +00:00
>>> import random
>>> import math
>>> def f1(x, y):
2021-09-29 10:04:04 +00:00
result = random.uniform(-1,1) * x**2 - math.sin(y**2) + abs(y-x)
return result
>>> def f2(x, y):
2021-09-29 10:04:04 +00:00
result = random.uniform(-1,1) * y**3 - math.cos(x**2) + 2*x
return result
>>> g = GenerativeImage(f1, f2)
2021-09-29 10:04:04 +00:00
>>> g.generate()
>>> g.plot()
>>> g.seed
188781
>>> plt.show()
2021-09-29 09:18:45 +00:00
```
2021-09-29 10:04:04 +00:00
<img src="https://github.com/sepandhaghighi/samila/raw/master/otherfiles/images/1.png">
2021-09-29 09:18:45 +00:00
### Projection
```pycon
2021-09-29 10:04:04 +00:00
>>> from samila import Projection
>>> g = GenerativeImage(f1, f2)
2021-09-29 10:04:04 +00:00
>>> g.generate()
>>> g.plot(projection=Projection.POLAR)
>>> g.seed
829730
>>> plt.show()
2021-09-29 09:18:45 +00:00
```
2021-09-29 10:04:04 +00:00
<img src="https://github.com/sepandhaghighi/samila/raw/master/otherfiles/images/2.png">
2021-09-29 09:18:45 +00:00
2021-09-29 14:37:35 +00:00
* Supported projections : `RECTILINEAR`, `POLAR`, `AITOFF`, `HAMMER`, `LAMBERT` and `MOLLWEIDE`
* Default projection is `RECTILINEAR`
2021-09-29 09:18:45 +00:00
### Range
```pycon
>>> g = GenerativeImage(f1, f2)
>>> g.generate(start=-2*math.pi, step=0.01, stop=0)
2021-09-29 10:04:04 +00:00
>>> g.plot()
>>> g.seed
234752
>>> plt.show()
2021-09-29 09:18:45 +00:00
```
2021-09-29 10:04:04 +00:00
<img src="https://github.com/sepandhaghighi/samila/raw/master/otherfiles/images/3.png">
2021-09-29 09:18:45 +00:00
### Color
```pycon
>>> g = GenerativeImage(f1, f2)
2021-09-29 10:04:04 +00:00
>>> g.generate()
>>> g.plot(color="yellow", bgcolor="black", projection=Projection.POLAR)
2021-09-29 10:04:04 +00:00
>>> g.seed
1018273
>>> plt.show()
2021-09-29 09:18:45 +00:00
```
2021-09-29 10:04:04 +00:00
<img src="https://github.com/sepandhaghighi/samila/raw/master/otherfiles/images/4.png">
2021-09-29 09:18:45 +00:00
2021-09-29 14:37:35 +00:00
* Supported colors are available in `VALID_COLORS` list
* `color` and `bgcolor` parameters support color name and RGB/RGBA formats
2021-09-29 10:04:04 +00:00
### Regeneration
```pycon
>>> g = GenerativeImage(f1, f2)
2021-09-29 10:04:04 +00:00
>>> g.generate(seed=1018273)
>>> g.plot(projection=Projection.POLAR)
>>> plt.show()
```
<img src="https://github.com/sepandhaghighi/samila/raw/master/otherfiles/images/5.png">
2021-09-29 09:18:45 +00:00
2021-09-30 01:22:33 +00:00
### NFT.storage
Upload generated image directly to [NFT.storage](https://NFT.storage)
```pycon
>>> g.nft_storage(api_key=YOUR_API_KEY)
2021-09-30 01:22:33 +00:00
{'status': True, 'message': 'Everything seems good'}
```
2021-11-04 07:26:41 +00:00
### Save image
2021-10-12 13:06:24 +00:00
Save generated image
```pycon
>>> g.save_image(file_adr="test.png")
{'status': True, 'message': 'Everything seems good'}
```
2021-10-15 15:12:02 +00:00
Save generated image in higher resolutions
2021-10-14 12:09:07 +00:00
```pycon
2021-10-14 13:04:31 +00:00
>>> g.save_image(file_adr="test.png", depth=5)
2021-10-14 12:09:07 +00:00
{'status': True, 'message': 'Everything seems good'}
```
2021-10-12 13:06:24 +00:00
2021-10-23 17:17:44 +00:00
### Save data
2021-11-04 07:26:41 +00:00
Save generated image data
2021-10-23 17:17:44 +00:00
```pycon
2022-01-17 13:43:06 +00:00
>>> g.save_data(file_adr="data.json")
2021-10-23 17:17:44 +00:00
```
So you can load it into a `GenerativeImage` instance later by
```pycon
2022-01-17 13:43:06 +00:00
>>> g = GenerativeImage(data=open('data.json', 'r'))
2021-10-23 17:17:44 +00:00
```
2022-01-17 14:00:38 +00:00
Data structure:
```
{
"plot": {
"projection": "polar",
"bgcolor": "black",
"color": "snow",
"spot_size": 0.01
},
"matplotlib_version": "3.0.3",
"data1": [
0.3886741692042526,
22.57390286376703,
-0.1646310981668766,
66.23632344600155
...
],
"data2": [
-0.14588750183600108,
20.197945942677833,
0.5485453260942901,
-589.3284610518896
...
2022-01-17 14:00:38 +00:00
]
}
```
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 config
Save generated image config. It contains string formats of functions which is also human readable.
```pycon
>>> g.save_config(file_adr="config.json")
```
So you can load it into a `GenerativeImage` instance later by
```pycon
>>> g = GenerativeImage(config=open('config.json', 'r'))
```
2022-01-17 14:00:38 +00:00
Config structure:
```
{
"matplotlib_version": "3.0.3",
"generate": {
"seed": 379184,
"stop": 3.141592653589793,
"step": 0.01,
"start": -3.141592653589793
},
"f2": "random.uniform(-1,1)*math.cos(x*(y**3))+random.uniform(-1,1)*math.ceil(y-x)",
"f1": "random.uniform(-1,1)*math.ceil(y)-random.uniform(-1,1)*y**2+random.uniform(-1,1)*abs(y-x)",
2022-01-17 14:00:38 +00:00
"plot": {
"color": "snow",
"bgcolor": "black",
"projection": "polar",
"spot_size": 0.01
}
}
```
2021-10-07 21:09:54 +00:00
## Mathematical details
2021-10-11 15:26:43 +00:00
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).
2021-10-08 04:40:44 +00:00
### Example
<img src="https://github.com/sepandhaghighi/samila/raw/master/otherfiles/mathematical_details/transformation.png">
2021-10-11 15:18:12 +00:00
We have set of points in the first space (left square) which can be define as follow:
2021-10-11 06:29:57 +00:00
2021-10-07 08:48:55 +00:00
<img src="https://github.com/sepandhaghighi/samila/raw/master/otherfiles/mathematical_details/S1.jpg">
2021-10-07 21:09:54 +00:00
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
```
2021-10-07 08:48:55 +00:00
<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)
```
2021-10-07 08:48:55 +00:00
<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">
2021-09-29 09:18:45 +00:00
## Issues & bug reports
2021-10-30 08:31:24 +00:00
Just fill an issue and describe it. We'll check it ASAP!
2021-09-29 09:18:45 +00:00
2021-10-30 08:31:24 +00:00
- Please complete the issue template
You can also join our discord server
2021-10-30 08:31:47 +00:00
2021-10-30 08:31:24 +00:00
<a href="https://discord.com/invite/94bz5QGZWb">
<img src="https://img.shields.io/discord/900055829225562162.svg?style=for-the-badge" alt="Discord Channel">
</a>
2021-09-29 09:18:45 +00:00
## 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>
## References
2021-09-30 11:41:38 +00:00
<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>
2021-09-29 09:18:45 +00:00
## Show your support
<h3>Star this repo</h3>
Give a ⭐️ if this project helped you!
<h3>Donate to our project</h3>
If you do like our project and we hope that you do, can you please support us? Our project is not and is never going to be working for profit. We need the money just so we can continue doing what we do ;-) .
<h4>Bitcoin</h4>
1KtNLEEeUbTEK9PdN6Ya3ZAKXaqoKUuxCy
<h4>Ethereum</h4>
0xcD4Db18B6664A9662123D4307B074aE968535388
<h4>Litecoin</h4>
Ldnz5gMcEeV8BAdsyf8FstWDC6uyYR6pgZ
<h4>Doge</h4>
DDUnKpFQbBqLpFVZ9DfuVysBdr249HxVDh
<h4>Tron</h4>
TCZxzPZLcJHr2qR3uPUB1tXB6L3FDSSAx7
<h4>Ripple</h4>
rN7ZuRG7HDGHR5nof8nu5LrsbmSB61V1qq
<h4>Binance Coin</h4>
bnb1zglwcf0ac3d0s2f6ck5kgwvcru4tlctt4p5qef
<h4>Tether</h4>
0xcD4Db18B6664A9662123D4307B074aE968535388
<h4>Dash</h4>
Xd3Yn2qZJ7VE8nbKw2fS98aLxR5M6WUU3s
2021-10-13 08:15:30 +00:00
<h4>Stellar</h4>
2021-09-29 09:18:45 +00:00
GALPOLPISRHIYHLQER2TLJRGUSZH52RYDK6C3HIU4PSMNAV65Q36EGNL
2021-10-13 08:15:30 +00:00
<h4>Zilliqa</h4>
zil1knmz8zj88cf0exr2ry7nav9elehxfcgqu3c5e5
2021-10-13 08:18:03 +00:00
<h4>Coffeete</h4>
2021-10-13 08:15:30 +00:00
<a href="http://www.coffeete.ir/opensource">
<img src="http://www.coffeete.ir/images/buttons/lemonchiffon.png" style="width:260px;" />
</a>
2021-09-29 09:18:45 +00:00