用于生成Julia集图形和动画的命令行工具
项目描述
Julia Art "juliart"
此模块基于Color Julia Bot,但旨在命令行生成,并可以选择根据主题(假日、季节)自定义颜色,还可以生成动画。名称“juliart”也是一个双关语(Juliard),暗示艺术性。
我已经尽力让默认参数产生(我认为)最随机、最漂亮的图像。当然,您可以按需调整参数,如下所述!
示例和文档
如果您想查看示例,请查看以下存储库
- vsoch/juliart-says:在Julia集图像上写入马尔可夫生成(或原始)文本
- vsoch/juliart-grid:一组Julia集,以显示Mandelbrot集的索引
- vsoch.github.io:关于Juliart的概述,解释了Julia和Mandelbrot集。
使用方法
安装
您可以从pypi安装
pip install juliart
或直接从存储库安装
$ git clone https://github.com/vsoch/juliart
$ python setup.py install
对于动画,您还需要一个额外的软件包
pip install juliart[animate]
生成艺术作品
您可以在终端中输入juliart
来查看基本用法
$ juliart
usage: juliart [-h] [--version] {generate,animate} ...
Julia Set art generator
optional arguments:
-h, --help show this help message and exit
--version suppress additional output.
actions:
actions for Julia Set art generator
{generate,animate} juliart actions
generate generate a Julia Set image
animate create a Julia Set animation (gif)
您会看到有两个选项:生成和动画
生成
生成命令的定制通常包括颜色或主题选择、可选的要在图形上打印的文本以及参数。
$ juliart generate --help
usage: juliart generate [-h] [--radius RADIUS] [--outfile OUTFILE]
[--text TEXT] [--fontsize FONTSIZE] [--xcoord XCOORD]
[--ycoord YCOORD] [--ca CA] [--cb CB] [--res RES]
[--iter ITERS] [--color {random,pattern,glow}]
[--rgb RGB]
[--theme {christmas,easter,fall,random,halloween,hanukkah,spring,summer,thanksgiving,valentine,winter}]
[--zoom ZOOM]
optional arguments:
-h, --help show this help message and exit
--radius RADIUS the max radius to allow (default is 4)
--outfile OUTFILE the output file to save the image (defaults to
randomly generated png)
--text TEXT write a string of text to bottom left corner
--fontsize FONTSIZE font size of text (if desired) defaults to 16
--xcoord XCOORD x coordinate for text (defaults to 0)
--ycoord YCOORD y coordinate for text (defaults to 0)
--ca CA the a component of the c parameter
--cb CB the b component of the c parameter
--res RES the resolution to generate (defaults to 1000)
--iter ITERS the number of iterations per pixel (defaults to 200)
--color {random,pattern,glow}
a color pattern to follow.
--rgb RGB a specific rbg color, in format R,G,B
--theme {christmas,easter,fall,random,halloween,hanukkah,spring,summer,thanksgiving,valentine,winter}
a theme to color the art (defaults to random colors)
--zoom ZOOM the level of zoom (defaults to 1.8)
默认值
如果您使用默认值,它将在当前工作目录中生成一个随机命名的图像。
$ juliart generate
Generating Julia Set...
Saving image to doopy-kerfuffle-5780.png
C 参数
ca 和 cb(Julia 集合方程中 c 参数的实部和虚部)的值是随机选择的,但您可以选择它们以更好地了解您的选择如何影响图形生成。
juliart generate --ca 0.5 --cb 0.5
我还创建了一个小项目,它将直观地显示您的参数选择如何影响生成的图像!您可能希望给输出文件一个更有意义的名字。
juliart generate --ca 0.5 --cb 0.5 --outfile ca-0.5-cb-0.5.png
如果您打算比较图像,设置一致的颜色也是合理的。
juliart generate --ca 0.5 --cb 0.5 --outfile ca-0.5-cb-0.5.png --rgb 90,12,10
对于这个练习的更深入探讨(我很好奇),请参阅Juliart Grid。
文本
作为文件名的替代(或者只是为了好玩!)您还可以生成带有自定义消息的图像。
juliart generate --text "Dinosaurs are great!"
默认情况下,文本将打印在左上角(坐标 10,10),但是您可以调整到您喜欢的位置。
$ juliart generate --text "Avocados are also great!" --xcoord 200 --ycoord 20
您还可以将字体从 OpenSans-Regular.ttf 更改为 Pacifico-Regular.ttf,并选择一个 alpha(透明度)。
$ juliart generate --text "Avocados!" --fontsize 30 --font-alpha 90 --font Pacifico-Regular
您可以在文本示例文件夹中查看所有这些示例。
缩放、迭代和半径
否则,您可以进行上述任何定制!尝试调整迭代次数、颜色/主题和缩放以查看不同的效果。
$ juliart generate --zoom 3
$ juliart generate --iter 100
经过一段时间的观察,我发现如果增加迭代值并修改半径,这将生成更详细的图像。以下是一些示例。
juliart generate --iter 1000 --radius 8
juliart generate --iter 5000 --radius 10
当然,这个过程会更长。
交互式 Python
以下是一个从 Python 中生成图像的快速示例
from juliart.main import JuliaSet
juliaset = JuliaSet(
resolution=1000, # (1000x1000)
color="random", # random, glow, pattern
theme="random",
rgb=None, # "197,18,12"
iterations=200,
)
juliaset.generate_image(zoom=1.8)
juliaset.save_image("/tmp/myimage.png")
如果您想添加文本,请在保存图像之前做
juliaset.write_text(
text,
fontsize=16,
xcoord=10,
ycoord=10,
)
默认情况下,文本是白色的。您可以通过以下方式更改颜色(并添加透明度,alpha 层)
juliaset.write_text(
text,
fontsize=16,
xcoord=10,
ycoord=10,
rgb=(255, 255, 255, 15),
)
动画
您可以按照以下方式检查动画命令的参数
$ juliart animate --help
usage: juliart animate [-h] [--no-cleanup] [--constant-a] [--constant-b]
[--randomize-zoom] [--zoom-max ZOOM_MAX]
[--zoom-min ZOOM_MIN] [--frames FRAMES]
[--outfile OUTFILE] [--text TEXT] [--fontsize FONTSIZE]
[--xcoord XCOORD] [--ycoord YCOORD] [--ca CA] [--cb CB]
[--res RES] [--iter ITERS]
[--color {random,pattern,glow}] [--rgb RGB]
[--theme {christmas,easter,fall,random,halloween,hanukkah,spring,summer,thanksgiving,valentine,winter}]
[--zoom ZOOM]
optional arguments:
-h, --help show this help message and exit
--no-cleanup Do not delete temporary directory with png files to
generate gif.
--constant-a Don't randomize the point A on the circle.
--constant-b Don't randomize the point B on the circle.
--randomize-zoom Randomize the zoom up to --zoom-min or --zoom-max.
--zoom-max ZOOM_MAX the max zoom (must be greater than 3)
--zoom-min ZOOM_MIN the max zoom (must be greater than 0)
--frames FRAMES the number of frames to generate (default is 30)
--outfile OUTFILE the output file to save the image (defaults to
randomly generated png)
--text TEXT write a string of text to bottom left corner
--fontsize FONTSIZE font size of text (if desired) defaults to 16
--xcoord XCOORD x coordinate for text (defaults to 0)
--ycoord YCOORD y coordinate for text (defaults to 0)
--ca CA the a component of the c parameter
--cb CB the b component of the c parameter
--res RES the resolution to generate (defaults to 1000)
--iter ITERS the number of iterations per pixel (defaults to 200)
--color {random,pattern,glow}
a color pattern to follow.
--rgb RGB a specific rbg color, in format R,G,B
--theme {christmas,easter,fall,random,halloween,hanukkah,spring,summer,thanksgiving,valentine,winter}
a theme to color the art (defaults to random colors)
--zoom ZOOM the level of zoom (defaults to 1.8)
大多数默认值(最小值和最大值)都是相当合理的,您可能不想更改它们。默认情况下,我们将改变用于生成 Julia 集合的 A 和 B 常数,但不会改变缩放。
默认值
默认情况下,将生成一个 30 帧、参数 A 和 B 变化但缩放不变、分辨率为(1000 X 1000)和 200 迭代的动画。
$ juliart animate --frames 5
优化
当然,您可以通过更改迭代次数和分辨率来加快速度!
$ juliart animate --res 500 --iters 100
权衡是图像质量。您还会注意到,在生成黑色像素的情况下,所需时间比白色像素略长(因为白色是颜色缺失)。
文本
您可以在动画的所有帧中添加一个一致的消息
juliart animate --text "Dinosaurs are great!"
并自定义 --xcoord
、--ycoord
或 --fontsize
参数。有关示例,请参阅文本示例文件夹。如果您想在帧之间变化文本,则需要自己编写循环来生成帧,然后将其组合成动画。示例代码可在Juliart Grid中找到。
清理
如果您想保留临时 png 图像(帧),可以这样做
$ juliart animate --no-cleanup
帧
如果您想自定义帧数,也可以这样做(我们默认为30)。这里将生成更小、更快的图像
$ juliart animate --frames 5
缩放
要随机化缩放,请指定
$ juliart animate --randomize-zoom --frames 5
Python
在Python中生成相对简单
from juliart.main import JuliaSetAnimation
juliaset = JuliaSetAnimation(
resolution=args.res,
color=args.color,
theme=args.theme,
rgb=args.rgb,
cleanup=not args.skip_cleanup,
iterations=args.iters,
zoom_max=args.zoom_max,
zoom_min=args.zoom_min,
)
juliaset.generate_animation(
zoom=args.zoom,
outfile=args.outfile,
frames=args.frames,
randomize_a=not args.constant_a,
randomize_b=not args.constant_b,
randomize_zoom=args.randomize_zoom,
)
颜色
颜色有三种选择:随机、图案或光晕,或者设置自己的RGB值。
随机
默认是随机,这里README顶部的图像就是使用此设置生成的。请查看更多随机示例。
图案
图案不使用渐变,而是返回颜色(和黑色)之间的硬边界。
请在此处查看更多图案示例。
RGB
如果您想要完全控制颜色,请提供如下逗号分隔的RGB数字列表
$ juliart generate --rgb 9,35,155
请注意,这也可以与--color pattern
标志一起使用。
光晕
光晕意味着暗背景(黑色)和颜色渐变。这里是一个示例
并且如下生成
juliart generate --color glow
请查看更多光晕示例。
如果您选择光晕,这将覆盖下一个主题的选择(接下来讨论)。
主题
为了在颜色选择中获得更多多样性,您可以选择一个主题!
juliart generate --theme halloween
juliart generate --theme christmas
juliart generate --theme hanukkah
juliart generate --theme thanksgiving
juliart generate --theme valentine
juliart generate --theme easter
juliart generate --theme fall
juliart generate --theme spring
juliart generate --theme summer
juliart generate --theme winter
对于上述任何命令,您也可以添加--color pattern
来将背景从主题颜色翻转至黑色。
$ juliart generate --theme halloween --color pattern
请查看主题文件夹中的图像以了解颜色调色板。
Docker
您也可以运行预先生成的Docker容器!您需要将主机上的文件夹绑定以保存图像。
$ mkdir data
$ docker run -it -v $PWD/data/:/data quay.io/vanessa/juliart generate --outfile /data/art.png
如果您喜欢,也可以先构建图像
$ docker build -t quay.io/vanessa/juliart .
图像在quay.io/vanessa/juliart上提供。
支持
您有问题吗?或者想要建议一个功能来使其更好?请提交问题!
项目详情
下载文件
下载您平台上的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。
源分发
构建分发
juliart-0.0.16.tar.gz的散列值
算法 | 散列摘要 | |
---|---|---|
SHA256 | 9a9c071ed9a8b65aeff80adabe1c61884b025af126a9997b7dacfd4f96dd10de |
|
MD5 | 86bf0df91d03580eee1d067292f1cab0 |
|
BLAKE2b-256 | 06e8ca2c370ca7f75eb6d834dccd8be8b6a4d8a8dff789835a82408d19297452 |