Skip to main content

Generative ART

Project description


Samila


built with Python3 PyPI version Samila-Colab Discord Channel

Table of contents

Overview

Samila is a generative art generator written in Python, Samila let's you create arts based on many thousand points. The position of every single point is calculated by a formula, which has random parameters. Because of the random numbers, every image looks different.

Open Hub
PyPI Counter
Github Stars
Branch master dev
CI
Code Quality codebeat badge CodeFactor

Installation

Source code

  • Download Version 0.7 or Latest Source
  • 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

Easy install

  • Run easy_install --upgrade samila (Need root access)

Usage

Magic

>>> import matplotlib.pyplot as plt
>>> from samila import GenerativeImage
>>> g = GenerativeImage()
>>> g.generate()
>>> g.plot()
>>> plt.show()

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()

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

Range

>>> g = GenerativeImage(f1, f2)
>>> g.generate(start=-2*math.pi, step=0.01, stop=0)
>>> g.plot()
>>> g.seed
234752
>>> plt.show()

Color

>>> g = GenerativeImage(f1, f2)
>>> g.generate()
>>> g.plot(color="yellow", bgcolor="black", projection=Projection.POLAR)
>>> g.seed
1018273
>>> plt.show()
  • Supported colors are available in VALID_COLORS list

  • color and bgcolor parameters supported formats:

    1. Color name (example: yellow)
    2. RGB/RGBA (example: (0.1,0.1,0.1), (0.1,0.1,0.1,0.1))
    3. Hex (example: #eeefff)
    4. Random (example: random)

Regeneration

>>> g = GenerativeImage(f1, f2)
>>> g.generate(seed=1018273)
>>> g.plot(projection=Projection.POLAR)
>>> plt.show()

NFT.storage

Upload generated image directly to NFT.storage

>>> g.nft_storage(api_key="YOUR_API_KEY")
{'status': True, 'message': 'FILE_LINK'}

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
    }
}

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 define as follow:

And bellow 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 uses 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! :

Binder

Google Colab

  • Check examples folder

Issues & bug reports

Just fill an issue and describe it. We'll check it ASAP!

  • Please complete the issue template

You can also join our discord server

Discord Channel

Dependencies

master dev
Requirements Status Requirements Status

Social media

  1. Instagram
  2. Telegram
  3. Twitter
  4. Discord

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

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 ;-) .

Bitcoin

1KtNLEEeUbTEK9PdN6Ya3ZAKXaqoKUuxCy

Ethereum

0xcD4Db18B6664A9662123D4307B074aE968535388

Litecoin

Ldnz5gMcEeV8BAdsyf8FstWDC6uyYR6pgZ

Doge

DDUnKpFQbBqLpFVZ9DfuVysBdr249HxVDh

Tron

TCZxzPZLcJHr2qR3uPUB1tXB6L3FDSSAx7

Ripple

rN7ZuRG7HDGHR5nof8nu5LrsbmSB61V1qq

Binance Coin

bnb1zglwcf0ac3d0s2f6ck5kgwvcru4tlctt4p5qef

Tether

0xcD4Db18B6664A9662123D4307B074aE968535388

Dash

Xd3Yn2qZJ7VE8nbKw2fS98aLxR5M6WUU3s

Stellar

GALPOLPISRHIYHLQER2TLJRGUSZH52RYDK6C3HIU4PSMNAV65Q36EGNL

Zilliqa

zil1knmz8zj88cf0exr2ry7nav9elehxfcgqu3c5e5

Coffeete

Gitcoin

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

0.7 - 2022-05-04

Added

  • fill_data function
  • random_hex_color_gen function
  • color,bgcolor and projection parameters random mode

Changed

  • Calculation warning added to generate method
  • Hex color support for color and bgcolor parameters
  • Test system modified
  • Random mode modified
  • filter_color function modified
  • filter_projection function modified
  • is_same_data function modified
  • README.md updated

0.6 - 2022-04-13

Added

  • save_params_filter function

Changed

  • __del__ method updated
  • message field changed in save_fig_file function
  • message field changed in save_config_file function
  • message field changed in save_data_file function
  • message field changed in nft_storage_upload function
  • depth section added to config/data file
  • linewidth parameter added to plot method
  • linewidth parameter added to plot_params_filter function
  • Random mode modified
  • README.md updated

0.5 - 2022-03-21

Added

  • __del__ method
  • Demo notebook

Changed

  • depth parameter added to nft_storage method
  • depth parameter added to save_fig_buf function
  • alpha parameter added to plot method
  • alpha parameter added to plot_params_filter function
  • Random mode modified
  • README.md updated

0.4 - 2022-01-13

Added

  • PLOT_DATA_ERROR error message
  • _GI_initializer function
  • generate_params_filter function
  • plot_params_filter function
  • filter_size function
  • save_config method
  • load_config function
  • save_config_file function
  • samilaConfigError class
  • samilaPlotError class
  • filter_float function
  • Random equations mode
  • function1_str attribute
  • function2_str attribute

Changed

  • README.md updated
  • plot section added to data file
  • edgecolor changed to c in plot method
  • config parameter added to GenerativeImage __init__
  • filter_projection function edited
  • Test system updated

Removed

  • NO_FUNCTION_ERROR error message
  • DATA_PARSING_ERROR error message
  • JUST_DATA_WARNING warning message

0.3 - 2021-11-10

Added

  • Discord channel
  • load_data function
  • save_data_file function
  • save_data method

Changed

  • data parameter added to GenerativeImage __init__
  • depth parameter added to save_image method
  • depth parameter added to save_fig_file function
  • save_image and nft_storage methods background bug fixed
  • README.md updated
  • Test system updated
  • Python 3.10 added to test.yml

0.2 - 2021-10-14

Added

  • dependabot.yml
  • requirements-splitter.py
  • samila_help function
  • test.py
  • function_test.py
  • overall_test.py
  • nft_upload_test.py
  • is_same_data function
  • save_image method

Changed

  • dev-requirements.txt updated
  • README.md updated
  • __main__.py updated
  • Test system updated
  • nft_storage method updated

0.1 - 2021-09-30

Added

  • GenerativeImage class
  • plot method
  • generate method
  • nft_storage method

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

samila-0.7.tar.gz (20.5 kB view details)

Uploaded Source

Built Distribution

samila-0.7-py3-none-any.whl (16.8 kB view details)

Uploaded Python 3

File details

Details for the file samila-0.7.tar.gz.

File metadata

  • Download URL: samila-0.7.tar.gz
  • Upload date:
  • Size: 20.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.4

File hashes

Hashes for samila-0.7.tar.gz
Algorithm Hash digest
SHA256 45e6526d0a48b4778222d6a546806a01a1fb543640ec2c11d0ad778f68e9afc7
MD5 3998133d81a29827bedca5ced9f5f0dd
BLAKE2b-256 13c7156e4a511440e209b680e37ca26016e6aabc87cfe942b16443f513d86c26

See more details on using hashes here.

File details

Details for the file samila-0.7-py3-none-any.whl.

File metadata

  • Download URL: samila-0.7-py3-none-any.whl
  • Upload date:
  • Size: 16.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.4

File hashes

Hashes for samila-0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 03168e8217625b9da7e1c10bcf26c1826f304aa093109eabbebefcdbdf05ac6d
MD5 5b07e85bb258444166bbbb057afe1168
BLAKE2b-256 d3c56350b7f37690bbed151d0d1685e734fd794f6cfb5c365fee58e58da8933e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page