• Stars
    star
    1,087
  • Rank 42,594 (Top 0.9 %)
  • Language
    Python
  • License
    MIT License
  • Created about 3 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Generative Art Generator

Samila


built with Python3 PyPI version Samila-Colab Discord Channel

Table of contents

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 codebeat badge CodeFactor

Installation

Source code

  • Download Version 1.1 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)

Conda

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

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

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: color="yellow")
    2. RGB/RGBA (example: color=(0.1,0.1,0.1), color=(0.1,0.1,0.1,0.1))
    3. Hex (example: color="#eeefff")
    4. Random (example: color="random")
    5. Complement (example: color="complement", bgcolor="blue")
    6. Transparent (example: bgcolor="transparent")
    7. 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()

NFT.storage

Upload generated image directly to NFT.storage

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

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

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

>>> 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 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! :

Binder

Google Colab

  • Check examples folder

Issues & bug reports

Just fill an issue and describe it. We'll check it ASAP! or send an email to [email protected].

  • Please complete the issue template

You can also join our discord server

Discord Channel

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

More Repositories

1

art

🎨 ASCII art library for Python
Python
2,100
star
2

pycm

Multi-class confusion matrix library in Python
Python
1,444
star
3

pyrgg

🔧 Python Random Graph Generator
Python
203
star
4

nafas

🧘‍♂️ Breathing Gymnastics Application
Python
118
star
5

mytimer

A Geeky Timer for Terminal Enthusiasts
Python
102
star
6

qpage

👨‍💻 Free Project For Creating Academic Homepage Without Any Code In 3min
Python
97
star
7

python-questions

نمونه سوال های برنامه نویسی پایتون
75
star
8

csv2latex

🔧 Simple script in python to convert CSV files to LaTeX table
Python
60
star
9

findip

🔧 Python Script For Finding All Available Local IP Addresses
Python
42
star
10

lightsout

🎲 Lights Out Game
JavaScript
33
star
11

Energy-Calculator

🌏 Simple Energy-Calculator Script In Python
Python
32
star
12

pyshutdown

📚 Python shutdown library
Python
31
star
13

penney

Penney's Game
Python
26
star
14

gitfollow

Github follower and following
Python
26
star
15

mnimi

🎲 Mnimi (A Game of Memory Skill)
JavaScript
25
star
16

telecheck

Simple CLI Tool For Generating Available Telegram Usernames
Python
15
star
17

verilogparser

Simple Verilog Parser In Python
Python
14
star
18

Ethereum-Fraud-Detection-Models

Ethereum Fraud Detection Models
Jupyter Notebook
10
star
19

csv2yaml

🔧 Quick & Easy CSV To JSON, YAML & Pickle Converter
Python
10
star
20

mycoffee

☕ Brew Perfect Coffee Right from Your Terminal
Python
10
star
21

boardroom

Boardroom API in Python
Python
7
star
22

Ethereum-Fraud-Detection-Visualization

Ethereum Fraud Detection Visualization
Jupyter Notebook
7
star
23

ipz

📚 Simple lib for extracting local and global ip in python scripts
Python
7
star
24

sepandhaghighi.github.io

HTML
6
star
25

zstyle

Z-Style : Generative Z-Style Avatars
Python
5
star
26

cennznet-nft

Cennznet NFT
Python
4
star
27

pyerror

Python
4
star
28

longevity

3
star
29

IOT_Hardware

IOT_Hardware
Arduino
3
star
30

shaghighi.ir

shaghighi.ir website redirection
HTML
3
star
31

appketab

AppKetab Project Site
SCSS
3
star
32

hadoop

Anagram Python Script In Hadoop
Python
3
star
33

pycm.ir

pycm.ir website redirection
HTML
3
star
34

Green-HW

Green Computing HW
Batchfile
2
star
35

tkinter

Training GUI in Python
Python
2
star
36

e-energy

HTML
2
star
37

Integer-Squaring

Integer Squaring Algorithm
Python
2
star
38

logicx

Python
2
star
39

Green-Project

Green Computing Course Final Project
Cuda
2
star
40

iranfidget

CSS
2
star
41

test_anaconda

Python
2
star
42

4r7.ir

4r7.ir website redirection
HTML
2
star
43

PSOAS

Plastic Surgeries Outcome Assessment Software
Visual Basic
1
star
44

PRL

Fourier Optic And Image Processing
MATLAB
1
star
45

VLSI-Lib

SourcePawn
1
star
46

CPP

Advance C++ Programming - 2015
C++
1
star
47

pycounter

Python projects line counter
Python
1
star
48

hobabak

Hobabak Static Site
CSS
1
star
49

sourena

Sourenashimi test website
1
star