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>

编辑推荐精选

Trae

Trae

字节跳动发布的AI编程神器IDE

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

AI工具TraeAI IDE协作生产力转型热门
问小白

问小白

全能AI智能助手,随时解答生活与工作的多样问题

问小白,由元石科技研发的AI智能助手,快速准确地解答各种生活和工作问题,包括但不限于搜索、规划和社交互动,帮助用户在日常生活中提高效率,轻松管理个人事务。

热门AI助手AI对话AI工具聊天机器人
Transly

Transly

实时语音翻译/同声传译工具

Transly是一个多场景的AI大语言模型驱动的同声传译、专业翻译助手,它拥有超精准的音频识别翻译能力,几乎零延迟的使用体验和支持多国语言可以让你带它走遍全球,无论你是留学生、商务人士、韩剧美剧爱好者,还是出国游玩、多国会议、跨国追星等等,都可以满足你所有需要同传的场景需求,线上线下通用,扫除语言障碍,让全世界的语言交流不再有国界。

讯飞智文

讯飞智文

一键生成PPT和Word,让学习生活更轻松

讯飞智文是一个利用 AI 技术的项目,能够帮助用户生成 PPT 以及各类文档。无论是商业领域的市场分析报告、年度目标制定,还是学生群体的职业生涯规划、实习避坑指南,亦或是活动策划、旅游攻略等内容,它都能提供支持,帮助用户精准表达,轻松呈现各种信息。

AI办公办公工具AI工具讯飞智文AI在线生成PPTAI撰写助手多语种文档生成AI自动配图热门
讯飞星火

讯飞星火

深度推理能力全新升级,全面对标OpenAI o1

科大讯飞的星火大模型,支持语言理解、知识问答和文本创作等多功能,适用于多种文件和业务场景,提升办公和日常生活的效率。讯飞星火是一个提供丰富智能服务的平台,涵盖科技资讯、图像创作、写作辅助、编程解答、科研文献解读等功能,能为不同需求的用户提供便捷高效的帮助,助力用户轻松获取信息、解决问题,满足多样化使用场景。

热门AI开发模型训练AI工具讯飞星火大模型智能问答内容创作多语种支持智慧生活
Spark-TTS

Spark-TTS

一种基于大语言模型的高效单流解耦语音令牌文本到语音合成模型

Spark-TTS 是一个基于 PyTorch 的开源文本到语音合成项目,由多个知名机构联合参与。该项目提供了高效的 LLM(大语言模型)驱动的语音合成方案,支持语音克隆和语音创建功能,可通过命令行界面(CLI)和 Web UI 两种方式使用。用户可以根据需求调整语音的性别、音高、速度等参数,生成高质量的语音。该项目适用于多种场景,如有声读物制作、智能语音助手开发等。

咔片PPT

咔片PPT

AI助力,做PPT更简单!

咔片是一款轻量化在线演示设计工具,借助 AI 技术,实现从内容生成到智能设计的一站式 PPT 制作服务。支持多种文档格式导入生成 PPT,提供海量模板、智能美化、素材替换等功能,适用于销售、教师、学生等各类人群,能高效制作出高品质 PPT,满足不同场景演示需求。

讯飞绘文

讯飞绘文

选题、配图、成文,一站式创作,让内容运营更高效

讯飞绘文,一个AI集成平台,支持写作、选题、配图、排版和发布。高效生成适用于各类媒体的定制内容,加速品牌传播,提升内容营销效果。

热门AI辅助写作AI工具讯飞绘文内容运营AI创作个性化文章多平台分发AI助手
材料星

材料星

专业的AI公文写作平台,公文写作神器

AI 材料星,专业的 AI 公文写作辅助平台,为体制内工作人员提供高效的公文写作解决方案。拥有海量公文文库、9 大核心 AI 功能,支持 30 + 文稿类型生成,助力快速完成领导讲话、工作总结、述职报告等材料,提升办公效率,是体制打工人的得力写作神器。

openai-agents-python

openai-agents-python

OpenAI Agents SDK,助力开发者便捷使用 OpenAI 相关功能。

openai-agents-python 是 OpenAI 推出的一款强大 Python SDK,它为开发者提供了与 OpenAI 模型交互的高效工具,支持工具调用、结果处理、追踪等功能,涵盖多种应用场景,如研究助手、财务研究等,能显著提升开发效率,让开发者更轻松地利用 OpenAI 的技术优势。

下拉加载更多