Samila
A Generative Art Generator
Install / Use
/learn @sepandhaghighi/SamilaREADME
Overview
<p align="justify"> 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> <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> <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> <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/actions/workflows/test.yml/badge.svg?branch=master"></td> <td align="center"><img src="https://github.com/sepandhaghighi/samila/actions/workflows/test.yml/badge.svg?branch=dev"></td> </tr> </table> <table> <tr> <td align="center">Code Quality</td> <td><a href="https://app.codacy.com/gh/sepandhaghighi/samila/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade"><img src="https://app.codacy.com/project/badge/Grade/14df8ed5f8434aaea85889555b0182a9"/></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>Installation
PyPI
- Check Python Packaging User Guide
- Run
pip install samila==1.6
Source code
- Download Version 1.6 or Latest Source
- Run
pip install .
Conda
- Check Conda Managing Package
conda install -c sepandhaghighi samila
Usage
Magic
>>> 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">
ℹ️ You can change function generation seed by func_seed parameter in GenerativeImage
Basic
>>> import random
>>> import math
>>> 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()
>>> g.seed
188781
>>> plt.show()
<img src="https://github.com/sepandhaghighi/samila/raw/master/otherfiles/images/1.png">
Generation mode
>>> from samila import GenerateMode
>>> g = GenerativeImage(f1, f2)
>>> g.generate(mode=GenerateMode.F1_VS_INDEX)
>>> g.plot()
>>> g.seed
883114
>>> plt.show()
<img src="https://github.com/sepandhaghighi/samila/raw/master/otherfiles/images/10.png">
ℹ️ Supported modes : F1_VS_F2, F2_VS_F1, F1_VS_INDEX, F2_VS_INDEX, INDEX_VS_F1, INDEX_VS_F2, F1_VS_X1, F1_VS_X2, F2_VS_X1, F2_VS_X2, X1_VS_F1, X1_VS_F2, X2_VS_F1, X2_VS_F2, F1F2_VS_F1, F1F2_VS_F2, F1_VS_F1F2, F2_VS_F1F2 and RANDOM
ℹ️ Default mode is F1_VS_F2
Projection
>>> from samila import Projection
>>> g = GenerativeImage(f1, f2)
>>> g.generate()
>>> g.plot(projection=Projection.POLAR)
>>> g.seed
829730
>>> plt.show()
<img src="https://github.com/sepandhaghighi/samila/raw/master/otherfiles/images/2.png">
ℹ️ Supported projections : RECTILINEAR, POLAR, AITOFF, HAMMER, LAMBERT, MOLLWEIDE and RANDOM
ℹ️ Default projection is RECTILINEAR
Marker
>>> 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.
>>> g = GenerativeImage(f1, f2)
>>> g.generate()
>>> g.plot(rotation=45)
ℹ️ Default rotation is 0
Range
>>> g = GenerativeImage(f1, f2)
>>> g.generate(start=-2*math.pi, step=0.01, stop=0)
>>> g.plot()
>>> g.seed
234752
>>> plt.show()
<img src="https://github.com/sepandhaghighi/samila/raw/master/otherfiles/images/3.png">
ℹ️ Default range is $(-\pi, \pi)$
Color
>>> g = GenerativeImage(f1, f2)
>>> g.generate()
>>> g.plot(color="yellow", bgcolor="black", projection=Projection.POLAR)
>>> g.seed
1018273
>>> plt.show()
<img src="https://github.com/sepandhaghighi/samila/raw/master/otherfiles/images/4.png">
ℹ️ Default color is black
ℹ️ Default background-color is white
ℹ️ Supported colors are available in VALID_COLORS list
ℹ️ color and bgcolor parameters supported formats:
- Color name (example:
color="yellow") - RGB/RGBA (example:
color=(0.1,0.1,0.1),color=(0.1,0.1,0.1,0.1)) - Hex (example:
color="#eeefff") - Random (example:
color="random") - Complement (example:
color="complement", bgcolor="blue") - Transparent (example:
bgcolor="transparent") - List (example:
color=["black", "#fffeef",...])
⚠️ Transparent mode is only available for background
⚠️ List mode is only available for color
⚠️ In List mode, the length of this list must be equal to the lengths of data1 and data2
Point color
You can make your custom color map and use it in Samila.
>>> colorarray = [
... [0.7, 0.2, 0.2, 1],
... [0.6, 0.3, 0.2, 1],
... "black",
... [0.4, 0.4, 0.3, 1],
... [0.3, 0.4, 0.4, 1],
... "#ff2561"]
>>> g.generate()
>>> g.seed
454893
>>> g.plot(cmap=colorarray, color=g.data2, projection=Projection.POLAR)
>>> plt.show()
<img src="https://github.com/sepandhaghighi/samila/raw/master/otherfiles/images/8.png">
Regeneration
>>> g = GenerativeImage(f1, f2)
>>> g.generate(seed=1018273)
>>> g.plot(projection=Projection.POLAR)
>>> plt.show()
<img src="https://github.com/sepandhaghighi/samila/raw/master/otherfiles/images/5.png">
Save image
Save generated image.
>>> g.save_image(file_adr="test.png")
{'status': True, 'message': 'FILE_PATH'}
Save generated image in higher resolutions.
>>> g.save_image(file_adr="test.png", depth=5)
{'status': True, 'message': 'FILE_PATH'}
Save data
Save generated image data.
>>> g.save_data(file_adr="data.json")
{'status': True, 'message': 'FILE_PATH'}
So you can load it into a GenerativeImage instance later by
>>> g = GenerativeImage(data=open('data.json', 'r'))
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
]
}
Save config
Save generated image config. It contains string formats of functions which is also human readable.
>>> g.save_config(file_adr="config.json")
{'status': True, 'message': 'FILE_PATH'}
So you can load it into a GenerativeImage instance later by
>>> g = GenerativeImage(config=open('config.json', 'r'))
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)",
"plot": {
"color": "snow",
"bgcolor": "black",
"projection": "polar",
"spot_size": 0.01
}
}
