Skip to content

Samila


目录

概述

Samila是一个使用python语言的生成艺术生成器,通过数千个点你可以生成自己的艺术品。每一个单点的位置都通过带随机参数的公式确定。因为随机数的存在,每一张生成的图片看起来都不一样。

安装

源码

  • 下载 版本 0.3 或者 最新源码
  • 运行 pip install -r requirements.txtpip3 install -r requirements.txt (需要管理员权限)
  • 运行 python3 setup.py installpython setup.py install (需要管理员权限)

PyPI

  • 查看 Python包用户指南
  • 运行 pip install samila==0.3pip3 install samila==0.3 (需要管理员权限)

Easy install

  • 运行 easy_install --upgrade samila (需要管理员权限)

使用

基本使用方法

>>> import random
>>> import math
>>> import matplotlib.pyplot as plt
>>> from samila import GenerativeImage
>>> 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()

投影

>>> from samila import Projection
>>> g = GenerativeImage(f1,f2)
>>> g.generate()
>>> g.plot(projection=Projection.POLAR)
>>> g.seed
829730
>>> plt.show()

  • 支持的投影方法 : RECTILINEAR, POLAR, AITOFF, HAMMER, LAMBERTMOLLWEIDE
  • 默认投影为 RECTILINEAR

范围

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

颜色

>>> g = GenerativeImage(f1,f2)
>>> g.generate()
>>> g.plot(color="yellow",bgcolor="black",projection=Projection.POLAR)
>>> g.seed
1018273
>>> plt.show()

  • 支持颜色请查看 VALID_COLORS 列表
  • colorbgcolor 参数支持VALID_COLORS 列表内的颜色名和RGB/RGBA格式

重复生成

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

NFT.storage

把生成图片直接上传至 NFT.storage

>>> g.nft_storage(api_key = YOUR_API_KEY)
{'status': True, 'message': 'Everything seems good'}

保存图片

保存生成图片

>>> g.save_image(file_adr="test.png")
{'status': True, 'message': 'Everything seems good'}
保存高清图片

>>> g.save_image(file_adr="test.png", depth=5)
{'status': True, 'message': 'Everything seems good'}

保存数据

保存生成图像数据

>>> g.save_data(file_adr="test.json")
随后可以通过以下代码加载至GenerativeImage实例:

>>> g = GenerativeImage(data=open('test.json', 'r'))

数学细节

Samila的原理很简单,只是对一个方形空间进行从笛卡尔坐标系到其他专用坐标系(比如极坐标)的转换操作。

比如在左边的方块,我们有一组符合以下定义的点:

\[S_1 = \{(x,y)| - \pi < x < \pi, -\pi < y < \pi \}\]

以下两个函数用于转换:

>>> 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
$$ S_2 = \lbrace (f_1(x,y), f_2(x,y))|(x,y) \in S_1\rbrace $$

这里传入参数为极坐标 Projection.POLAR ,所以最后我们得到极坐标空间图:

>>> g = GenerativeImage(f1,f2)
>>> g.generate(seed=10)
>>> g.plot(projection=Projection.POLAR)
$$ S_2' = \lbrace (r, \theta) = (Z * x^2 - \sin(y^2) + |y-x|, Z * y^3 - \cos(x^2) + 2x) | (x,y) \in S_1, Z \sim U(-1,1) \rbrace $$

问题 & Bug上报

请直接写issue并详细描述。我们会尽快检查!

  • 请参照issue模板完成提交

你也可以加入我们的discord频道:

Discord Channel

参考

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

支持

给我们星标

如果觉得这个项目有帮助到你请给个 ⭐️ !

捐助项目

真心希望你能喜欢我们的项目,能提供点支持吗?我们的项目不是也不会以赢利为目标。我们需要钱以继续维护这个项目;-) 。