Animated Asemia
Publish date: Apr 16, 2021
Last updated: Apr 16, 2021
Last updated: Apr 16, 2021
import ipywidgets as widgets
def render(step=0):
page = document(80, 80, 'mm').addpage()
page.place(shape().nostroke().fill(rgb(255, 255, 255)).rectangle(0, 0, 80, 80))
page.place(shape().nostroke().fill(rgb(40, 40, 160)).ellipse(40, 40, step, step*1.5))
return page
width = 120
height = 160
d = document(width, height, 'mm')
page = d.addpage()
def brush(a, b, c, d):
return shape().nostroke().fill(rgba( uniform(a, b), uniform(c, d) , 40 ,160)).width(0.8).join('round')
grid_size = 30
cell_size_x = width / 8
cell_size_y = height / 12
def render(step =0):
for i in range(step):
for j in range(24):
scale_val = (width / grid_size) * 0.4
x = i+2.1 * cell_size_x + (cell_size_x * uniform(0.2, 1.2)) + uniform(-10, 20)
y = j * cell_size_y + (cell_size_y * 0.4) + uniform(-2, 2)
glyph = uniform_glyph_baseline(4)
glyph = glyph.scale(uniform(6,12)).translate(x, y)
# glyph_curve = glyph.augment().smooth_path(tightness=4)
glyph_curve = glyph.augment().fancy_curve(tightness= -10, samples_per=10, thicknesses=[0.1, 1.1, 0.6, 0.2, 0.8, 1])
# note .path() here, not .polyline()!
page.place(brush(i*10,200-j*20,150-i*12, j*20).polyline(glyph_curve))
return page
return page
#show(page)
# show(render(20))
def render_and_show(step=0):
show(render(step))
# widgets.interact(render_and_show, step=widgets.Play(min=0, max=30, interval=1000/30))
#!pip install cairosvg
from IPython.display import display, Image, HTML
def page2png(page, dpi=72):
try:
import cairosvg
png_bytes = cairosvg.svg2png(page.svg(), dpi=dpi)
except ModuleNotFoundError:
png_bytes = page.image(ppi=dpi, kind='rgb').png()
return png_bytes
# png_data = page2png(render(10))
# display(Image(png_data))
for i in range(30):
fname = f"render/image{i:05}.png"
png_data = page2png(render(i))
with open(fname, "wb") as fh:
fh.write(png_data)
!ffmpeg -loglevel warning -y \
-framerate 30 -f image2 -i render/image%05d.png \
-filter_complex "[0:v] split [a][b];[a] palettegen [p];[b][p] paletteuse" render/output4.gif