samila

samila

Python生成艺术库创造随机独特图像

Samila是一个Python生成艺术库,能基于数千个随机计算的点创建独特图像。它支持多种投影方式、标记类型和颜色选项,可生成富有表现力的艺术作品。Samila还提供图像保存、重现和NFT上传功能,方便数字艺术创作。每次生成的图像都呈现不同效果,为艺术家提供了无限可能。

Samila生成艺术Python图像生成数学公式Github开源项目
<div align="center"> <img src="https://yellow-cdn.veclightyear.com/0a4dffa0/19e319e5-5867-4169-8845-360389b29ca9.png" width=400 height=400> <br/> <h1>Samila</h1> <br/> <a href="https://www.python.org/"> <img src="https://yellow-cdn.veclightyear.com/0a4dffa0/86b68135-455c-48d6-8785-473876a7adea.svg" alt="使用Python3构建" /> </a> <a href="https://codecov.io/gh/sepandhaghighi/samila"> <img src="https://yellow-cdn.veclightyear.com/0a4dffa0/a471d44c-968f-48f6-83f9-55883e753ae9.svg" /> </a> <a href="https://badge.fury.io/py/samila"> <img src="https://yellow-cdn.veclightyear.com/0a4dffa0/0fc45da6-ff02-4a30-813c-031198be01b1.svg" alt="PyPI版本" height="18"> </a> <a href="https://anaconda.org/sepandhaghighi/samila"> <img src="https://yellow-cdn.veclightyear.com/0a4dffa0/b6a73fa1-f127-4364-aaff-592566b5485f.svg"> </a> <a href="https://colab.research.google.com/github/sepandhaghighi/samila/blob/master"> <img src="https://yellow-cdn.veclightyear.com/0a4dffa0/97795732-46f8-4cd9-b100-4dc4d18c1fef.svg" alt="Samila-Colab"/> </a> <a href="https://discord.com/invite/94bz5QGZWb"> <img src="https://yellow-cdn.veclightyear.com/0a4dffa0/999d2862-53a2-458b-94e1-810b29749beb.svg" alt="Discord频道"> </a> </div>

概述

<p align="justify"> Samila是一个用Python编写的生成艺术生成器,它允许你基于数千个点创建图像。每个点的位置都由一个具有随机参数的公式计算得出。由于随机数的存在,每幅图像看起来都不同。 </p> <table> <tr> <td align="center">Open Hub</td> <td align="center"><a href="https://www.openhub.net/p/samila"><img src="https://yellow-cdn.veclightyear.com/0a4dffa0/6fadca68-f2ec-4514-915d-bd8a243665af.gif"></a></td> </tr> <tr> <td align="center">PyPI计数器</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星标</td> <td align="center"><a href="https://github.com/sepandhaghighi/samila"><img src="https://yellow-cdn.veclightyear.com/0a4dffa0/805f81d7-570a-4934-b054-e1dc2e73a87e.svg?style=social&label=Stars"></a></td> </tr> </table> <table> <tr> <td align="center">分支</td> <td align="center">master</td> <td align="center">dev</td> </tr> <tr> <td align="center">CI</td> <td align="center"><img src="https://yellow-cdn.veclightyear.com/0a4dffa0/ac9a86cf-1f74-4753-b7c3-2efce52d84ed.svg?branch=master"></td> <td align="center"><img src="https://yellow-cdn.veclightyear.com/0a4dffa0/ac9a86cf-1f74-4753-b7c3-2efce52d84ed.svg?branch=dev"></td> </tr> </table> <table> <tr> <td align="center">代码质量</td> <td><a href="https://www.codacy.com/gh/sepandhaghighi/samila/dashboard?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=sepandhaghighi/samila&amp;utm_campaign=Badge_Grade"><img src="https://app.codacy.com/project/badge/Grade/14df8ed5f8434aaea85889555b0182a9"/></a></td> <td><a href="https://codebeat.co/projects/github-com-sepandhaghighi-samila-dev"><img alt="codebeat badge" src="https://codebeat.co/badges/01e6aa48-4cc2-4d9c-8288-c9fb490ad371" /></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>

安装

PyPI

源代码

Conda

使用

魔法

>>> import matplotlib.pyplot as plt >>> from samila import GenerativeImage >>> g = GenerativeImage() >>> g.generate() >>> g.plot() >>> plt.show()
<img src="https://yellow-cdn.veclightyear.com/0a4dffa0/5aec661d-9848-4798-a31d-37aa0968deea.png">
  • 你可以通过GenerativeImage中的func_seed参数更改函数生成种子

基础

>>> 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://yellow-cdn.veclightyear.com/0a4dffa0/09f5babd-7914-40d6-8e11-1a57e3cc985b.png">

投影

>>> from samila import Projection >>> g = GenerativeImage(f1, f2) >>> g.generate() >>> g.plot(projection=Projection.POLAR) >>> g.seed 829730 >>> plt.show()
<img src="https://yellow-cdn.veclightyear.com/0a4dffa0/0dc0dd1a-a092-424f-8328-2eb2a984de9a.png">
  • 支持的投影:RECTILINEAR, POLAR, AITOFF, HAMMER, LAMBERT, MOLLWEIDERANDOM
  • 默认投影为 RECTILINEAR

标记

>>> 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://yellow-cdn.veclightyear.com/0a4dffa0/84f71333-4141-46d8-bd25-a607950357ef.png">
  • 支持的标记:POINTPIXELCIRCLETRIANGLE_DOWNTRIANGLE_UPTRIANGLE_LEFTTRIANGLE_RIGHTTRI_DOWNTRI_UPTRI_LEFTTRI_RIGHTOCTAGONSQUAREPENTAGONPLUSPLUS_FILLEDSTARHEXAGON_VERTICALHEXAGON_HORIZONTALXX_FILLEDDIAMONDDIAMON_THINVLINEHLINERANDOM
  • 默认标记为POINT

旋转

你甚至可以使用rotation参数旋转你的艺术作品。输入你想要的图像旋转角度,你就能得到它。

>>> g = GenerativeImage(f1, f2) >>> g.generate() >>> g.plot(rotation=45)
  • 默认旋转角度为0

范围

>>> 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://yellow-cdn.veclightyear.com/0a4dffa0/53ce842e-f2d9-4b4b-a943-c54764f31321.png">

颜色

>>> g = GenerativeImage(f1, f2) >>> g.generate() >>> g.plot(color="yellow", bgcolor="black", projection=Projection.POLAR) >>> g.seed 1018273 >>> plt.show()
<img src="https://yellow-cdn.veclightyear.com/0a4dffa0/d93829d7-7c88-4623-adce-ed79a3f5be3b.png">
  • 可用的颜色在VALID_COLORS列表中

  • colorbgcolor参数支持的格式:

    1. 颜色名称(例如:color="yellow"
    2. RGB/RGBA(例如:color=(0.1,0.1,0.1)color=(0.1,0.1,0.1,0.1)
    3. 十六进制(例如:color="#eeefff"
    4. 随机(例如:color="random"
    5. 补色(例如:color="complement", bgcolor="blue"
    6. 透明(例如:bgcolor="transparent"
    7. 列表(例如:color=["black", "#fffeef",...]

⚠️ 透明模式仅适用于背景

⚠️ 列表模式仅适用于颜色

⚠️ 在列表模式下,此列表的长度必须等于data1和data2的长度

点颜色

你可以制作自定义颜色映射并在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://yellow-cdn.veclightyear.com/0a4dffa0/abd86c43-c62f-4320-8225-5de07ef1481e.png">

重新生成

>>> g = GenerativeImage(f1, f2) >>> g.generate(seed=1018273) >>> g.plot(projection=Projection.POLAR) >>> plt.show()
<img src="https://yellow-cdn.veclightyear.com/0a4dffa0/4ffdac20-48fe-4d84-bcd9-7de14d973b41.png">

NFT.storage

直接将生成的图像上传到NFT.storage

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

你也可以将配置/数据上传到NFT.storage,如下所示:

>>> g.nft_storage(api_key="API_KEY", upload_config=True) {'status': {'image': True, 'config':True}, 'message': {'image':'IMAGE_FILE_LINK', 'config':'CONFIG_FILE_LINK'}

>>> g.nft_storage(api_key="API_KEY", upload_data=True) {'status': {'image': True, 'data':True}, 'message': {'image':'IMAGE_FILE_LINK', 'data':'DATA_FILE_LINK'}

你可以选择特定的IPFS网关:

>>> from samila import Gateway >>> g.nft_storage(api_key="API_KEY", upload_data=True, gateway=Gateway.DWEB) {'status': {'image': True, 'data':True}, 'message': {'image':'IMAGE_FILE_LINK', 'data':'DATA_FILE_LINK'}
  • 默认超时时间为3000
  • 默认网关为IPFS_IO

保存图像

保存生成的图像

>>> g.save_image(file_adr="test.png") {'status': True, 'message': 'FILE_PATH'}

以更高分辨率保存生成的图像

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

保存数据

保存生成的图像数据

>>> g.save_data(file_adr="data.json") {'status': True, 'message': 'FILE_PATH'}

这样你之后可以通过以下方式将其加载到GenerativeImage实例中

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

数据结构:

{ "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 ] }

保存配置

保存生成的图像配置。它包含函数的字符串格式,也是人类可读的。

>>> g.save_config(file_adr="config.json") {'status': True, 'message': 'FILE_PATH'}

这样你之后可以通过以下方式将其加载到GenerativeImage实例中

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

配置结构:

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

数学细节

Samila 实质上是将笛卡尔坐标系中的方形空间转换为任意坐标系(如极坐标系)的变换。

示例

<img src="https://yellow-cdn.veclightyear.com/0a4dffa0/f6ff927b-0398-441d-96ff-fde897b54cc0.png">

我们在第一个空间(左侧方形)中有一组点,可以定义如下:

<img src="https://yellow-cdn.veclightyear.com/0a4dffa0/17d2a928-286e-4ce1-a804-9ca737dda2af.jpg">

以下函数用于转换:

>>> 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
<img src="https://yellow-cdn.veclightyear.com/0a4dffa0/c50de4d3-8b7a-431e-a766-fd32ce86d6ea.jpg">

这里我们使用 Projection.POLAR,所以后面的空间将是极坐标空间,我们有:

>>> g = GenerativeImage(f1, f2) >>> g.generate(seed=10) >>> g.plot(projection=Projection.POLAR)
<img src="https://yellow-cdn.veclightyear.com/0a4dffa0/dcf1ccfc-9f16-4356-840e-7563f7d65149.jpg"> <img src="https://yellow-cdn.veclightyear.com/0a4dffa0/bb3db8c7-ba00-4d99-a39c-8ccca51fa10b.png">

在浏览器中试用 Samila!

Samila 可以通过 Binder 或 Colab 服务在线使用交互式 Jupyter Notebooks!现在就来试试吧!:

Binder

Google Colab

  • 查看 examples 文件夹

问题与错误报告

只需填写一个 issue 并描述问题。我们会尽快检查!或发送电子邮件至 info@samila.site

  • 请完整填写 issue 模板

你也可以加入我们的 Discord 服务器

<a href="https://discord.com/invite/94bz5QGZWb"> <img src="https://yellow-cdn.veclightyear.com/0a4dffa0/999d2862-53a2-458b-94e1-810b29749beb.svg?style=for-the-badge" alt="Discord 频道"> </a>

社交媒体

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

参考文献

<blockquote>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.</blockquote> <blockquote>2- <a href="https://github.com/cutterkom/generativeart">使用 R 创建生成艺术</a></blockquote> <blockquote>3- <a href="https://nft.storage/">NFT.storage : 免费去中心化存储和 NFT 带宽</a></blockquote>

致谢

本项目由 Protocol Labs 设立的 Next Step Microgrant 计划资助。

表示支持

<h3>为这个仓库点星</h3>

如果这个项目对你有帮助,请给一个 ⭐️!

<h3>为我们的项目捐款</h3>

如果你喜欢我们的项目,我们希望你能支持我们。我们的项目现在不是也永远不会以盈利为目的。我们需要这笔钱只是为了继续我们正在做的事情 ;-) 。

<a href="http://www.samila.site/donate.html" target="_blank"><img src="https://yellow-cdn.veclightyear.com/0a4dffa0/3c6601f2-4f06-4b75-a430-5586d6a441bc.png" height="90px" width="270px" alt="Samila 捐款"></a>

编辑推荐精选

Vora

Vora

免费创建高清无水印Sora视频

Vora是一个免费创建高清无水印Sora视频的AI工具

Refly.AI

Refly.AI

最适合小白的AI自动化工作流平台

无需编码,轻松生成可复用、可变现的AI自动化工作流

酷表ChatExcel

酷表ChatExcel

大模型驱动的Excel数据处理工具

基于大模型交互的表格处理系统,允许用户通过对话方式完成数据整理和可视化分析。系统采用机器学习算法解析用户指令,自动执行排序、公式计算和数据透视等操作,支持多种文件格式导入导出。数据处理响应速度保持在0.8秒以内,支持超过100万行数据的即时分析。

AI工具酷表ChatExcelAI智能客服AI营销产品使用教程
TRAE编程

TRAE编程

AI辅助编程,代码自动修复

Trae是一种自适应的集成开发环境(IDE),通过自动化和多元协作改变开发流程。利用Trae,团队能够更快速、精确地编写和部署代码,从而提高编程效率和项目交付速度。Trae具备上下文感知和代码自动完成功能,是提升开发效率的理想工具。

AI工具TraeAI IDE协作生产力转型热门
AIWritePaper论文写作

AIWritePaper论文写作

AI论文写作指导平台

AIWritePaper论文写作是一站式AI论文写作辅助工具,简化了选题、文献检索至论文撰写的整个过程。通过简单设定,平台可快速生成高质量论文大纲和全文,配合图表、参考文献等一应俱全,同时提供开题报告和答辩PPT等增值服务,保障数据安全,有效提升写作效率和论文质量。

AI辅助写作AI工具AI论文工具论文写作智能生成大纲数据安全AI助手热门
博思AIPPT

博思AIPPT

AI一键生成PPT,就用博思AIPPT!

博思AIPPT,新一代的AI生成PPT平台,支持智能生成PPT、AI美化PPT、文本&链接生成PPT、导入Word/PDF/Markdown文档生成PPT等,内置海量精美PPT模板,涵盖商务、教育、科技等不同风格,同时针对每个页面提供多种版式,一键自适应切换,完美适配各种办公场景。

AI办公办公工具AI工具博思AIPPTAI生成PPT智能排版海量精品模板AI创作热门
潮际好麦

潮际好麦

AI赋能电商视觉革命,一站式智能商拍平台

潮际好麦深耕服装行业,是国内AI试衣效果最好的软件。使用先进AIGC能力为电商卖家批量提供优质的、低成本的商拍图。合作品牌有Shein、Lazada、安踏、百丽等65个国内外头部品牌,以及国内10万+淘宝、天猫、京东等主流平台的品牌商家,为卖家节省将近85%的出图成本,提升约3倍出图效率,让品牌能够快速上架。

iTerms

iTerms

企业专属的AI法律顾问

iTerms是法大大集团旗下法律子品牌,基于最先进的大语言模型(LLM)、专业的法律知识库和强大的智能体架构,帮助企业扫清合规障碍,筑牢风控防线,成为您企业专属的AI法律顾问。

SimilarWeb流量提升

SimilarWeb流量提升

稳定高效的流量提升解决方案,助力品牌曝光

稳定高效的流量提升解决方案,助力品牌曝光

Sora2视频免费生成

Sora2视频免费生成

最新版Sora2模型免费使用,一键生成无水印视频

最新版Sora2模型免费使用,一键生成无水印视频

下拉加载更多