A Generative Art Generator
Project description
Overview
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.
| Open Hub | |
| PyPI Counter | |
| Github Stars |
| Branch | master | dev |
| CI |
| Code Quality |
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()
ℹ️ 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()
Generation mode
>>> from samila import GenerateMode
>>> g = GenerativeImage(f1, f2)
>>> g.generate(mode=GenerateMode.F1_VS_INDEX)
>>> g.plot()
>>> g.seed
883114
>>> plt.show()
ℹ️ 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()
ℹ️ 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()
ℹ️ 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()
ℹ️ 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()
ℹ️ 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()
Regeneration
>>> g = GenerativeImage(f1, f2)
>>> g.generate(seed=1018273)
>>> g.plot(projection=Projection.POLAR)
>>> plt.show()
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
}
}
Command Line Interface (CLI)
You can easily create art directly from the command line with Samila CLI. Here's an example command to get started:
samila --color=red --bgcolor=black --rotation=30 --projection=polar --mode f2_vs_f1 --save-image test.png
In this example:
--color=red: Sets the primary color of the art.--bgcolor=black: Sets the background color.--rotation=30: Rotates the artwork by 30 degrees.--projection=polar: Use polar projection for plotting.--mode=f2_vs_f1: Sets the generation mode--save-image=test.png: Saves the generated image as test.png.
For more options and detailed usage, run the following command to access help:
samila --help
This will provide additional information on all available parameters and how to customize your artwork further.
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.
Example
We have set of points in the first space (left square) which can be defined as follow:
And below functions are used for transformation:
>>> 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
here we use Projection.POLAR so later space will be the polar space and we have:
>>> g = GenerativeImage(f1, f2)
>>> g.generate(seed=10)
>>> g.plot(projection=Projection.POLAR)
Try Samila in your browser!
Samila can be used online in interactive Jupyter Notebooks via the Binder or Colab services!
Try it out now!
ℹ️ Check examples folder
Issues & bug reports
Just fill an issue and describe it. We'll check it ASAP! or send an email to info@samila.site.
- Please complete the issue template
You can also join our discord server
Social media
References
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.
2- Create Generative Art with R
3- NFT.storage : Free decentralized storage and bandwidth for NFTs
Cite
If you use Samila in your research, we would appreciate citations to the following paper:
@article{sabouri2025samila,
title={Samila: A Generative Art Generator},
author={Sabouri, Sadra and Haghighi, Sepand and Masrour, Elena},
journal={arXiv preprint arXiv:2504.04298},
year={2025}
}
Acknowledgments
This project was funded through the Next Step Microgrant, a program established by Protocol Labs.
Show your support
Star this repo
Give a ⭐️ if this project helped you!
Donate to our project
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 ;-) .
Changelog
All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog and this project adheres to Semantic Versioning.
Unreleased
1.6 - 2025-07-16
Added
- 2 new generation modes
F1_VS_F1F2F2_VS_F1F2
Changed
README.mdupdateddemo.ipynbupdated- Test system modified
Python 3.6support dropped- Python typing features added to all modules
Removed
nft_storagemethodGatewayenum
1.5 - 2025-01-22
Added
- 3 new generation modes
RANDOMF1F2_VS_F1F1F2_VS_F2
Changed
- Elapsed time added to CLI
- CLI bug fixed
--function_seedargument renamed to--function-seed- Random mode modified
README.mdupdateddemo.ipynbupdated
1.4 - 2024-11-20
Added
- Command Line Interface (CLI)
Changed
- GitHub actions are limited to the
devandmasterbranches - Test system modified
Python 3.13added totest.yml
1.3 - 2024-09-09
Added
deprecatedfunction- 14 new generation modes
F1_VS_F2F2_VS_F1F1_VS_INDEXF2_VS_INDEXINDEX_VS_F1INDEX_VS_F2F1_VS_X1F2_VS_X1F1_VS_X2F2_VS_X2X1_VS_F1X1_VS_F2X2_VS_F1X2_VS_F2
bulk.ipynbnotebook
Changed
modeparameter added togeneratemethodREADME.mdupdateddemo.ipynbupdated
1.2 - 2024-06-25
Added
feature_request.ymltemplateconfig.ymlfor issue templateget_cmapfunctionGatewayenumSECURITY.md
Changed
- Bug report template modified
func_seedparameter added to GenerativeImage__init__- Minor edits in
functions.py DEFAULT_CMAPrenamed toDEFAULT_CMAP_NAMEpillowadded to conda dependenciescodecovremoved fromdev-requirements.txtgatewayparameter added tonft_storagemethod- Test system modified
- Random mode modified
README.mdupdatedPython 3.5support droppedPython 3.12added totest.yml
1.1 - 2023-04-05
Added
__version__attributepython_versionattributeget_python_versionfunctionRANDOM_EQUATION_MIN_COMPLEXITYparameterRANDOM_EQUATION_FOF_MAX_DEPTHparameterRANDOM_EQUATION_FOF_MIN_DEPTHparameterrotatefunction
Changed
rotationparameter added toplotmethodtimeoutparameter added tonft_storagemethodload_configfunction modifiednft_storage_uploadfunction modified- Random mode modified
RANDOM_EQUATION_GEN_COMPLEXITYparameter renamed toRANDOM_EQUATION_MAX_COMPLEXITYREADME.mdupdated
1.0 - 2022-12-14
Added
Markerenumget_datafunctionget_configfunction
Changed
markerparameter added toplotmethodupload_dataparameter added tonft_storagemethodupload_configparameter added tonft_storagemethodgeneratemethod optimized- Test system modified
README.mdupdatedPython 3.11added totest.ymlplotmethod warning bug fixed- Random mode modified
Removed
fill_datafunction
0.9 - 2022-09-28
Added
- Anaconda workflow
Changed
README.mdupdatedCODE_OF_CONDUCT.mdupdateddemo.ipynbupdatedcmapparameter added toplotmethod- Random mode modified
- Test system modified
generatemethod optimizedsamila_helpfunction updatedload_dataandload_configfunctions error handling updated
0.8 - 2022-06-01
Added
INVALID_COLOR_TYPE_ERRORerrorCOLOR_NOT_FOUND_WARNINGwarningBOTH_COLOR_COMPLEMENT_WARNINGwarningset_backgroundfunctionis_valid_colorfunctioncolor_complementfunctionselect_colorfunction
Changed
- Transparent mode support for
bgcolorparameter - Random mode modified
- Complementary color support for
colorandbgcolorparameters filter_colorfunction modified
0.7 - 2022-05-04
Added
fill_datafunctionrandom_hex_color_genfunctioncolor,bgcolorandprojectionparameters random mode
Changed
- Calculation warning added to
generatemethod - Hex color support for
colorandbgcolorparameters - Test system modified
- Random mode modified
filter_colorfunction modifiedfilter_projectionfunction modifiedis_same_datafunction modifiedREADME.mdupdated
0.6 - 2022-04-13
Added
save_params_filterfunction
Changed
__del__method updatedmessagefield changed insave_fig_filefunctionmessagefield changed insave_config_filefunctionmessagefield changed insave_data_filefunctionmessagefield changed innft_storage_uploadfunctiondepthsection added to config/data filelinewidthparameter added toplotmethodlinewidthparameter added toplot_params_filterfunction- Random mode modified
README.mdupdated
0.5 - 2022-03-21
Added
__del__method- Demo notebook
Changed
depthparameter added tonft_storagemethoddepthparameter added tosave_fig_buffunctionalphaparameter added toplotmethodalphaparameter added toplot_params_filterfunction- Random mode modified
README.mdupdated
0.4 - 2022-01-13
Added
PLOT_DATA_ERRORerror message_GI_initializerfunctiongenerate_params_filterfunctionplot_params_filterfunctionfilter_sizefunctionsave_configmethodload_configfunctionsave_config_filefunctionsamilaConfigErrorclasssamilaPlotErrorclassfilter_floatfunction- Random equations mode
function1_strattributefunction2_strattribute
Changed
README.mdupdatedplotsection added to data fileedgecolorchanged tocinplotmethodconfigparameter added to GenerativeImage__init__filter_projectionfunction edited- Test system updated
Removed
NO_FUNCTION_ERRORerror messageDATA_PARSING_ERRORerror messageJUST_DATA_WARNINGwarning message
0.3 - 2021-11-10
Added
- Discord channel
load_datafunctionsave_data_filefunctionsave_datamethod
Changed
dataparameter added to GenerativeImage__init__methoddepthparameter added tosave_imagemethoddepthparameter added tosave_fig_filefunctionsave_imageandnft_storagemethods background bug fixedREADME.mdupdated- Test system updated
Python 3.10added totest.yml
0.2 - 2021-10-14
Added
dependabot.ymlrequirements-splitter.pysamila_helpfunctiontest.pyfunction_test.pyoverall_test.pynft_upload_test.pyis_same_datafunctionsave_imagemethod
Changed
dev-requirements.txtupdatedREADME.mdupdated__main__.pyupdated- Test system updated
nft_storagemethod updated
0.1 - 2021-09-30
Added
GenerativeImageclassplotmethodgeneratemethodnft_storagemethod
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file samila-1.6.tar.gz.
File metadata
- Download URL: samila-1.6.tar.gz
- Upload date:
- Size: 28.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
010944c122336a677b4fae2d012a9873eedcf2117bf8975b8d08140fac4a80dc
|
|
| MD5 |
17b8d92de4196bf3fb5431060e4253eb
|
|
| BLAKE2b-256 |
2d0620fc8cfec9321316e046a635406d1aa310ef884a0a3843e8a3665434084a
|
File details
Details for the file samila-1.6-py3-none-any.whl.
File metadata
- Download URL: samila-1.6-py3-none-any.whl
- Upload date:
- Size: 23.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c9b62a5ab55f99f3b0f49371ae306a29ce42640e9969626dbb7210727384ff00
|
|
| MD5 |
1d175fd1b752b06bb6a84ad9787562ce
|
|
| BLAKE2b-256 |
7ea7110cb422cafcc7802db3a8ba5dffae7a5c8665a2ebc24b62463c6cf2468c
|