{ "cells": [ { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Collecting https://github.com/aparrish/bezmerizing/archive/master.zip\n", " Using cached https://github.com/aparrish/bezmerizing/archive/master.zip\n", "Requirement already satisfied, skipping upgrade: flat>=0.0.3 in /Users/dalitstein/opt/anaconda3/lib/python3.8/site-packages (from bezmerizing==0.1.1) (0.3.2)\n", "Requirement already satisfied, skipping upgrade: scipy>=1.1.0 in /Users/dalitstein/opt/anaconda3/lib/python3.8/site-packages (from bezmerizing==0.1.1) (1.5.2)\n", "Requirement already satisfied, skipping upgrade: numpy>=1.16.0 in /Users/dalitstein/opt/anaconda3/lib/python3.8/site-packages (from bezmerizing==0.1.1) (1.19.2)\n", "Building wheels for collected packages: bezmerizing\n", " Building wheel for bezmerizing (setup.py) ... \u001b[?25ldone\n", "\u001b[?25h Created wheel for bezmerizing: filename=bezmerizing-0.1.1-py3-none-any.whl size=17284 sha256=04de41ed6594aab58c0557a75167a0c0bba2c466ac12402b21a21f147ea8dc1f\n", " Stored in directory: /private/var/folders/hc/h5gqmtw53sn2rcs7vth699h00000gn/T/pip-ephem-wheel-cache-m_axo61t/wheels/74/5a/7d/4a62c2490b6c6061916e41ae070caaed12664893aef1a56d7c\n", "Successfully built bezmerizing\n", "Installing collected packages: bezmerizing\n", " Attempting uninstall: bezmerizing\n", " Found existing installation: bezmerizing 0.1.1\n", " Uninstalling bezmerizing-0.1.1:\n", " Successfully uninstalled bezmerizing-0.1.1\n", "Successfully installed bezmerizing-0.1.1\n" ] } ], "source": [ "import sys\n", "!{sys.executable} -m pip install --upgrade https://github.com/aparrish/bezmerizing/archive/master.zip" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "from flat import document, rgb, rgba, font, strike, shape\n", "from flat.command import moveto, quadto, curveto, lineto, closepath\n", "from bezmerizing import Polyline, Path\n", "import numpy as np\n", "from copy import copy" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [], "source": [ "from numpy.random import uniform, normal, choice" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [], "source": [ "from IPython.display import SVG, display\n", "def show(page):\n", " display(SVG(page.svg()))" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [], "source": [ "f = font.open(\"fonts/plantc.ttf\")\n", "f1 = font.open(\"fonts/FrankRuhlLibre-Regular.ttf\")" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "Untitled\n", "\n", "\n", "\n", "Emotions\n", "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "d = document(80, 80, 'mm')\n", "page = d.addpage()\n", "pen = shape().stroke(rgba(0, 0, 0, 255)).fill(rgba(128, 128, 128, 255)).width(4)\n", "text_pen = strike(f1).color(rgba(0, 0, 0, 255)).size(24, 32)\n", "page.place(text_pen.text(\"Emotions\")).frame(10, 10, 60, 60)\n", "show(page)" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ,\n", " ]" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "f.glyph(38)" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Path([moveto(x=427.5000, y=-1329.5000), quadto(x1=593.0000, y1=-1417.0000, x=813.0000, y=-1417.0000), quadto(x1=969.0000, y1=-1417.0000, x=1137.0000, y=-1335.0000), quadto(x1=1159.0000, y1=-1325.0000, x=1178.5000, y=-1316.0000), quadto(x1=1198.0000, y1=-1307.0000, x=1212.0000, y=-1307.0000), quadto(x1=1245.0000, y1=-1307.0000, x=1255.0000, y=-1346.0000), quadto(x1=1259.0000, y1=-1361.0000, x=1287.0000, y=-1361.0000), quadto(x1=1317.0000, y1=-1361.0000, x=1317.0000, y=-1346.0000), lineto(x=1317.0000, y=-1343.0000), quadto(x1=1303.0000, y1=-1287.0000, x=1303.0000, y=-1204.0000), quadto(x1=1303.0000, y1=-1147.0000, x=1311.0000, y=-1089.5000), quadto(x1=1319.0000, y1=-1032.0000, x=1327.0000, y=-971.0000), quadto(x1=1327.0000, y1=-962.0000, x=1316.0000, y=-956.5000), quadto(x1=1305.0000, y1=-951.0000, x=1290.0000, y=-951.0000), quadto(x1=1258.0000, y1=-951.0000, x=1255.0000, y=-969.0000), quadto(x1=1156.0000, y1=-1327.0000, x=801.0000, y=-1327.0000), quadto(x1=588.0000, y1=-1327.0000, x=466.0000, y=-1166.5000), quadto(x1=344.0000, y1=-1006.0000, x=344.0000, y=-711.0000), quadto(x1=344.0000, y1=-522.0000, x=399.5000, y=-376.5000), quadto(x1=455.0000, y1=-231.0000, x=559.0000, y=-148.5000), quadto(x1=663.0000, y1=-66.0000, x=809.0000, y=-66.0000), quadto(x1=962.0000, y1=-66.0000, x=1045.5000, y=-102.0000), quadto(x1=1129.0000, y1=-138.0000, x=1191.5000, y=-235.5000), quadto(x1=1254.0000, y1=-333.0000, x=1276.0000, y=-477.0000), quadto(x1=1279.0000, y1=-498.0000, x=1302.0000, y=-498.0000), quadto(x1=1317.0000, y1=-498.0000, x=1330.5000, y=-489.0000), quadto(x1=1344.0000, y1=-480.0000, x=1344.0000, y=-473.0000), lineto(x=1343.0000, y=-469.0000), quadto(x1=1333.0000, y1=-401.0000, x=1333.0000, y=-307.0000), quadto(x1=1333.0000, y1=-252.0000, x=1348.0000, y=-12.0000), quadto(x1=1348.0000, y1=1.0000, x=1338.0000, y=7.0000), quadto(x1=1328.0000, y1=13.0000, x=1316.0000, y=13.0000), quadto(x1=1290.0000, y1=13.0000, x=1286.0000, y=-6.0000), quadto(x1=1279.0000, y1=-40.0000, x=1257.0000, y=-61.0000), quadto(x1=1235.0000, y1=-82.0000, x=1208.0000, y=-82.0000), quadto(x1=1186.0000, y1=-82.0000, x=1159.0000, y=-68.0000), quadto(x1=1067.0000, y1=-17.0000, x=989.5000, y=1.5000), quadto(x1=912.0000, y1=20.0000, x=795.0000, y=20.0000), quadto(x1=432.0000, y1=20.0000, x=257.0000, y=-161.0000), quadto(x1=82.0000, y1=-342.0000, x=82.0000, y=-680.0000), quadto(x1=82.0000, y1=-905.0000, x=172.0000, y=-1073.5000), quadto(x1=262.0000, y1=-1242.0000, x=427.5000, y=-1329.5000), closepath])" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "glyph_path = Path(f.glyph(38))\n", "glyph_path" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2048" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "f.density" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Path([moveto(x=15.0293, y=-46.7402), quadto(x1=20.8477, y1=-49.8164, x=28.5820, y=-49.8164), quadto(x1=34.0664, y1=-49.8164, x=39.9727, y=-46.9336), quadto(x1=40.7461, y1=-46.5820, x=41.4316, y=-46.2656), quadto(x1=42.1172, y1=-45.9492, x=42.6094, y=-45.9492), quadto(x1=43.7695, y1=-45.9492, x=44.1211, y=-47.3203), quadto(x1=44.2617, y1=-47.8477, x=45.2461, y=-47.8477), quadto(x1=46.3008, y1=-47.8477, x=46.3008, y=-47.3203), lineto(x=46.3008, y=-47.2148), quadto(x1=45.8086, y1=-45.2461, x=45.8086, y=-42.3281), quadto(x1=45.8086, y1=-40.3242, x=46.0898, y=-38.3027), quadto(x1=46.3711, y1=-36.2812, x=46.6523, y=-34.1367), quadto(x1=46.6523, y1=-33.8203, x=46.2656, y=-33.6270), quadto(x1=45.8789, y1=-33.4336, x=45.3516, y=-33.4336), quadto(x1=44.2266, y1=-33.4336, x=44.1211, y=-34.0664), quadto(x1=40.6406, y1=-46.6523, x=28.1602, y=-46.6523), quadto(x1=20.6719, y1=-46.6523, x=16.3828, y=-41.0098), quadto(x1=12.0938, y1=-35.3672, x=12.0938, y=-24.9961), quadto(x1=12.0938, y1=-18.3516, x=14.0449, y=-13.2363), quadto(x1=15.9961, y1=-8.1211, x=19.6523, y=-5.2207), quadto(x1=23.3086, y1=-2.3203, x=28.4414, y=-2.3203), quadto(x1=33.8203, y1=-2.3203, x=36.7559, y=-3.5859), quadto(x1=39.6914, y1=-4.8516, x=41.8887, y=-8.2793), quadto(x1=44.0859, y1=-11.7070, x=44.8594, y=-16.7695), quadto(x1=44.9648, y1=-17.5078, x=45.7734, y=-17.5078), quadto(x1=46.3008, y1=-17.5078, x=46.7754, y=-17.1914), quadto(x1=47.2500, y1=-16.8750, x=47.2500, y=-16.6289), lineto(x=47.2148, y=-16.4883), quadto(x1=46.8633, y1=-14.0977, x=46.8633, y=-10.7930), quadto(x1=46.8633, y1=-8.8594, x=47.3906, y=-0.4219), quadto(x1=47.3906, y1=0.0352, x=47.0391, y=0.2461), quadto(x1=46.6875, y1=0.4570, x=46.2656, y=0.4570), quadto(x1=45.3516, y1=0.4570, x=45.2109, y=-0.2109), quadto(x1=44.9648, y1=-1.4062, x=44.1914, y=-2.1445), quadto(x1=43.4180, y1=-2.8828, x=42.4688, y=-2.8828), quadto(x1=41.6953, y1=-2.8828, x=40.7461, y=-2.3906), quadto(x1=37.5117, y1=-0.5977, x=34.7871, y=0.0527), quadto(x1=32.0625, y1=0.7031, x=27.9492, y=0.7031), quadto(x1=15.1875, y1=0.7031, x=9.0352, y=-5.6602), quadto(x1=2.8828, y1=-12.0234, x=2.8828, y=-23.9062), quadto(x1=2.8828, y1=-31.8164, x=6.0469, y=-37.7402), quadto(x1=9.2109, y1=-43.6641, x=15.0293, y=-46.7402), closepath])" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "glyph_path.scale(72 / f.density)" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "Untitled\n", "\n", "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "glyph_path = Path(f.glyph(36)).translate(0, f.density).scale(72 / f.density * 0.400)\n", "page = document(40, 40, 'mm').addpage()\n", "pen = shape().stroke(rgb(40, 40, 40)).fill(rgb(240, 240, 240)).width(4)\n", "page.place(pen.path(glyph_path))\n", "show(page)" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [], "source": [ "all_indices = list(f.charmap.values())" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "309" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "len(all_indices)" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [], "source": [ "glyph_path_lengths = [(idx, len(f.glyph(idx))) for idx in all_indices]" ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [], "source": [ "unicode_lookup = {v: k for k, v in f.charmap.items()}" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [], "source": [ "import unicodedata" ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'LATIN CAPITAL LETTER G'" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "unicodedata.name(chr(unicode_lookup[42]))" ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1006" ] }, "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ "f.advances[f.charmap[ord(\"a\")]]" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [], "source": [ "def glyphcommands(f, ch):\n", " return Path([copy(cmd) for cmd in f.glyph(f.charmap[ord(ch)])])\n", "def advancefor(f, ch):\n", " return f.advances[f.charmap[ord(ch)]]" ] }, { "cell_type": "code", "execution_count": 31, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Path([moveto(x=807.0000, y=-23.0000), quadto(x1=807.0000, y1=0.0000, x=791.0000, y=0.0000), lineto(x=61.0000, y=0.0000), quadto(x1=40.0000, y1=0.0000, x=40.0000, y=-20.0000), quadto(x1=40.0000, y1=-32.0000, x=49.0000, y=-47.0000), quadto(x1=126.0000, y1=-189.0000, x=305.0000, y=-445.0000), quadto(x1=481.0000, y1=-698.0000, x=521.0000, y=-762.0000), quadto(x1=561.0000, y1=-826.0000, x=561.0000, y=-834.0000), quadto(x1=561.0000, y1=-849.0000, x=520.5000, y=-854.5000), quadto(x1=480.0000, y1=-860.0000, x=387.0000, y=-860.0000), quadto(x1=300.0000, y1=-860.0000, x=255.5000, y=-848.5000), quadto(x1=211.0000, y1=-837.0000, x=185.0000, y=-808.0000), quadto(x1=159.0000, y1=-779.0000, x=129.0000, y=-680.0000), quadto(x1=123.0000, y1=-664.0000, x=98.0000, y=-664.0000), quadto(x1=85.0000, y1=-664.0000, x=76.5000, y=-668.5000), quadto(x1=68.0000, y1=-673.0000, x=68.0000, y=-679.0000), lineto(x=68.0000, y=-682.0000), quadto(x1=86.0000, y1=-806.0000, x=86.0000, y=-907.0000), quadto(x1=86.0000, y1=-924.0000, x=111.0000, y=-924.0000), lineto(x=772.0000, y=-924.0000), quadto(x1=802.0000, y1=-924.0000, x=802.0000, y=-903.0000), quadto(x1=802.0000, y1=-893.0000, x=795.0000, y=-881.0000), quadto(x1=679.0000, y1=-685.0000, x=544.0000, y=-493.0000), quadto(x1=409.0000, y1=-304.0000, x=305.0000, y=-121.0000), quadto(x1=294.0000, y1=-104.0000, x=294.0000, y=-93.0000), quadto(x1=294.0000, y1=-76.0000, x=330.0000, y=-69.5000), quadto(x1=366.0000, y1=-63.0000, x=473.0000, y=-63.0000), quadto(x1=585.0000, y1=-63.0000, x=632.0000, y=-77.5000), quadto(x1=679.0000, y1=-92.0000, x=706.5000, y=-128.5000), quadto(x1=734.0000, y1=-165.0000, x=762.0000, y=-260.0000), quadto(x1=766.0000, y1=-275.0000, x=794.0000, y=-275.0000), quadto(x1=808.0000, y1=-275.0000, x=817.5000, y=-269.5000), quadto(x1=827.0000, y1=-264.0000, x=827.0000, y=-255.0000), lineto(x=827.0000, y=-252.0000), quadto(x1=807.0000, y1=-130.0000, x=807.0000, y=-23.0000), closepath])" ] }, "execution_count": 31, "metadata": {}, "output_type": "execute_result" } ], "source": [ "glyphcommands(f, \"z\")" ] }, { "cell_type": "code", "execution_count": 32, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "854" ] }, "execution_count": 32, "metadata": {}, "output_type": "execute_result" } ], "source": [ "advancefor(f, \"z\")" ] }, { "cell_type": "code", "execution_count": 33, "metadata": {}, "outputs": [], "source": [ "all_indices = list(f.charmap.values())" ] }, { "cell_type": "code", "execution_count": 34, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "309" ] }, "execution_count": 34, "metadata": {}, "output_type": "execute_result" } ], "source": [ "len(all_indices)" ] }, { "cell_type": "code", "execution_count": 35, "metadata": {}, "outputs": [], "source": [ "glyph_path_lengths = [(idx, len(f.glyph(idx))) for idx in all_indices]" ] }, { "cell_type": "code", "execution_count": 36, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[(3, 0),\n", " (5, 25),\n", " (4, 16),\n", " (6, 36),\n", " (7, 68),\n", " (8, 58),\n", " (9, 69),\n", " (10, 12),\n", " (11, 22),\n", " (12, 21),\n", " (13, 80),\n", " (14, 14)]" ] }, "execution_count": 36, "metadata": {}, "output_type": "execute_result" } ], "source": [ "glyph_path_lengths[:12]" ] }, { "cell_type": "code", "execution_count": 37, "metadata": {}, "outputs": [], "source": [ "M = \"Memory\"" ] }, { "cell_type": "code", "execution_count": 38, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2048" ] }, "execution_count": 38, "metadata": {}, "output_type": "execute_result" } ], "source": [ "f.density" ] }, { "cell_type": "code", "execution_count": 39, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "Untitled\n", "\n", "\n", "\n", "\n", "\n", "\n", "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "page = document(300, 90, 'pt').addpage()\n", "pen = shape().nostroke().fill(rgba(0, 0, 0, 255))\n", "factor = 50 / f.density\n", "cx = 0\n", "for ch in M:\n", " glyph_path = glyphcommands(f, ch).scale(factor).translate(cx +50, 60)\n", " page.place(pen.path(glyph_path))\n", " cx += advancefor(f, ch) * factor\n", "show(page)" ] }, { "cell_type": "code", "execution_count": 40, "metadata": {}, "outputs": [], "source": [ "from itertools import chain\n", "def combine_path(f, M):\n", " text_paths = []\n", " cx = 0\n", " for ch in M:\n", " glyph_path = glyphcommands(f, ch).translate(cx, 0)\n", " text_paths.append(glyph_path)\n", " cx += advancefor(f, ch)\n", " combined = Path(list(chain(*text_paths)))\n", " return combined" ] }, { "cell_type": "code", "execution_count": 41, "metadata": {}, "outputs": [], "source": [ "qf_path = combine_path(f, \"Memory\")" ] }, { "cell_type": "code", "execution_count": 42, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "311" ] }, "execution_count": 42, "metadata": {}, "output_type": "execute_result" } ], "source": [ "len(qf_path.commands)" ] }, { "cell_type": "code", "execution_count": 43, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "Untitled\n", "\n", "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "page = document(300, 90, 'pt').addpage()\n", "pen = shape().nostroke().fill(rgba(0, 0, 0, 255))\n", "factor = 36 / f.density\n", "page.place(pen.path(qf_path.scale(factor).translate(50, 60)))\n", "show(page)" ] }, { "cell_type": "code", "execution_count": 44, "metadata": {}, "outputs": [], "source": [ "M_path_orig = glyphcommands(f, \"M\")" ] }, { "cell_type": "code", "execution_count": 45, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Path([moveto(x=262.0000, y=-272.0000), lineto(x=262.0000, y=-1126.0000), quadto(x1=262.0000, y1=-1201.0000, x=248.5000, y=-1237.0000), quadto(x1=235.0000, y1=-1273.0000, x=202.5000, y=-1290.5000), quadto(x1=170.0000, y1=-1308.0000, x=78.0000, y=-1315.0000), quadto(x1=66.0000, y1=-1315.0000, x=58.5000, y=-1326.0000), quadto(x1=51.0000, y1=-1337.0000, x=51.0000, y=-1350.0000), quadto(x1=51.0000, y1=-1362.0000, x=58.5000, y=-1372.0000), quadto(x1=66.0000, y1=-1382.0000, x=78.0000, y=-1382.0000), lineto(x=134.0000, y=-1382.0000), quadto(x1=501.0000, y1=-1382.0000, x=508.0000, y=-1354.0000), lineto(x=924.0000, y=-377.0000), quadto(x1=928.0000, y1=-371.0000, x=933.0000, y=-371.0000), quadto(x1=938.0000, y1=-371.0000, x=942.0000, y=-377.0000), lineto(x=1352.0000, y=-1354.0000), quadto(x1=1355.0000, y1=-1367.0000, x=1512.0000, y=-1374.5000), quadto(x1=1669.0000, y1=-1382.0000, x=1765.0000, y=-1382.0000), quadto(x1=1788.0000, y1=-1382.0000, x=1788.0000, y=-1350.0000), quadto(x1=1788.0000, y1=-1319.0000, x=1765.0000, y=-1315.0000), quadto(x1=1696.0000, y1=-1303.0000, x=1657.0000, y=-1292.5000), quadto(x1=1618.0000, y1=-1282.0000, x=1599.5000, y=-1254.5000), quadto(x1=1581.0000, y1=-1227.0000, x=1577.0000, y=-1173.5000), quadto(x1=1573.0000, y1=-1120.0000, x=1573.0000, y=-1022.0000), lineto(x=1573.0000, y=-266.0000), quadto(x1=1573.0000, y1=-177.0000, x=1587.5000, y=-139.0000), quadto(x1=1602.0000, y1=-101.0000, x=1639.5000, y=-83.5000), quadto(x1=1677.0000, y1=-66.0000, x=1772.0000, y=-57.0000), quadto(x1=1784.0000, y1=-55.0000, x=1791.0000, y=-44.0000), quadto(x1=1798.0000, y1=-33.0000, x=1798.0000, y=-21.0000), quadto(x1=1798.0000, y1=-8.0000, x=1791.0000, y=2.0000), quadto(x1=1784.0000, y1=12.0000, x=1769.0000, y=12.0000), quadto(x1=1688.0000, y1=12.0000, x=1613.0000, y=4.0000), quadto(x1=1538.0000, y1=-4.0000, x=1464.0000, y=-4.0000), quadto(x1=1386.0000, y1=-4.0000, x=1303.5000, y=4.0000), quadto(x1=1221.0000, y1=12.0000, x=1153.0000, y=12.0000), quadto(x1=1141.0000, y1=12.0000, x=1134.5000, y=2.0000), quadto(x1=1128.0000, y1=-8.0000, x=1128.0000, y=-21.0000), quadto(x1=1128.0000, y1=-33.0000, x=1134.5000, y=-44.0000), quadto(x1=1141.0000, y1=-55.0000, x=1153.0000, y=-57.0000), quadto(x1=1252.0000, y1=-66.0000, x=1288.0000, y=-84.5000), quadto(x1=1324.0000, y1=-103.0000, x=1337.0000, y=-141.5000), quadto(x1=1350.0000, y1=-180.0000, x=1350.0000, y=-266.0000), lineto(x=1350.0000, y=-1026.0000), quadto(x1=1350.0000, y1=-1039.0000, x=1336.0000, y=-1039.0000), quadto(x1=1317.0000, y1=-1039.0000, x=1313.0000, y=-1026.0000), lineto(x=1018.0000, y=-332.0000), quadto(x1=979.0000, y1=-242.0000, x=899.0000, y=-4.0000), quadto(x1=895.0000, y1=8.0000, x=869.0000, y=8.0000), quadto(x1=842.0000, y1=8.0000, x=838.0000, y=-4.0000), lineto(x=387.0000, y=-1036.0000), quadto(x1=382.0000, y1=-1049.0000, x=367.0000, y=-1049.0000), quadto(x1=356.0000, y1=-1049.0000, x=356.0000, y=-1034.0000), lineto(x=356.0000, y=-272.0000), quadto(x1=356.0000, y1=-199.0000, x=368.5000, y=-158.0000), quadto(x1=381.0000, y1=-117.0000, x=404.5000, y=-96.5000), quadto(x1=428.0000, y1=-76.0000, x=463.0000, y=-68.5000), quadto(x1=498.0000, y1=-61.0000, x=545.0000, y=-55.0000), quadto(x1=565.0000, y1=-51.0000, x=565.0000, y=-21.0000), quadto(x1=565.0000, y1=12.0000, x=543.0000, y=12.0000), quadto(x1=498.0000, y1=12.0000, x=443.5000, y=4.0000), quadto(x1=389.0000, y1=-4.0000, x=315.0000, y=-4.0000), quadto(x1=238.0000, y1=-4.0000, x=177.5000, y=4.0000), quadto(x1=117.0000, y1=12.0000, x=76.0000, y=12.0000), quadto(x1=65.0000, y1=12.0000, x=58.5000, y=0.5000), quadto(x1=52.0000, y1=-11.0000, x=52.0000, y=-24.0000), quadto(x1=52.0000, y1=-51.0000, x=76.0000, y=-55.0000), quadto(x1=129.0000, y1=-61.0000, x=165.0000, y=-68.5000), quadto(x1=201.0000, y1=-76.0000, x=222.5000, y=-96.5000), quadto(x1=244.0000, y1=-117.0000, x=253.0000, y=-158.0000), quadto(x1=262.0000, y1=-199.0000, x=262.0000, y=-272.0000), closepath])" ] }, "execution_count": 45, "metadata": {}, "output_type": "execute_result" } ], "source": [ "M_path_orig" ] }, { "cell_type": "code", "execution_count": 46, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "Untitled\n", "\n", "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "page = document(144, 144, 'pt').addpage()\n", "pen = shape().stroke(rgb(40, 40, 40)).fill(rgb(240, 240, 240))\n", "page.place(pen.path(M_path_orig.scale(144/f.density).translate(0, 144)))\n", "show(page)\n" ] }, { "cell_type": "code", "execution_count": 47, "metadata": {}, "outputs": [], "source": [ "M_path = glyphcommands(f, \"M\")\n", "for cmd in M_path.commands:\n", " if hasattr(cmd, 'x') and hasattr(cmd, 'y'):\n", " cmd.x += normal(0, 24)\n", " cmd.y += normal(0, 24)" ] }, { "cell_type": "code", "execution_count": 48, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "Untitled\n", "\n", "\n", "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "page = document(288, 144, 'pt').addpage()\n", "pen = shape().nostroke().fill(rgb(240, 240, 240))\n", "page.place(pen.path(M_path_orig.scale(144/f.density).translate(0, 144)))\n", "page.place(pen.path(M_path.scale(144/f.density).translate(144, 144)))\n", "show(page)" ] }, { "cell_type": "code", "execution_count": 49, "metadata": {}, "outputs": [], "source": [ "def nudge(cmd, x, y):\n", " c = copy(cmd)\n", " if type(cmd) in (moveto, lineto, quadto, curveto):\n", " c.x += x\n", " c.y += y\n", " if type(cmd) in (quadto, curveto):\n", " c.x1 += x\n", " c.y1 += y\n", " if type(cmd) == curveto:\n", " c.x2 += x\n", " c.y2 += y\n", " return c" ] }, { "cell_type": "code", "execution_count": 50, "metadata": {}, "outputs": [], "source": [ "from bezmerizing import PolylineList" ] }, { "cell_type": "code", "execution_count": 51, "metadata": {}, "outputs": [], "source": [ "qf_path_orig = combine_path(f, \"Memory\")\n", "qf_plist = qf_path_orig.to_polyline_list(samples_per=14)\n", "qf_path_orig = combine_path(f1, \" ן ו ר כ י ז\")\n", "qf_plist1 = qf_path_orig.to_polyline_list(samples_per=14)" ] }, { "cell_type": "code", "execution_count": 52, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "Untitled\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "page = document(400, 120, 'pt').addpage()\n", "pen = shape().nostroke().fill(rgba(255, 0, 255, 128))\n", "pen1 = shape().nostroke().fill(rgba(255, 0, 0, 128))\n", "factor = 40 / f.density\n", "factor1 = 80 / f.density\n", "for poly in qf_plist:\n", " page.place(pen.polygon(poly.scale(factor).translate(0, 90)))\n", "for poly in qf_plist1:\n", " page.place(pen1.polygon(poly.scale(factor1).translate(0, 90)))\n", "show(page)" ] }, { "cell_type": "code", "execution_count": 72, "metadata": {}, "outputs": [], "source": [ "mod_plist = qf_plist.map(lambda p: Polyline(p.vertices + \n", " np.stack([np.sin(p.vertices[:,1]*0.01)*20,\n", " np.cos(p.vertices[:,0]*0.01)*20], axis=1)))\n", "mod_plist1 = qf_plist1.map(lambda p: Polyline(p.vertices + \n", " np.stack([np.sin(p.vertices[:,1]*0.01)*20,\n", " np.cos(p.vertices[:,0]*0.01)*20], axis=1)))" ] }, { "cell_type": "code", "execution_count": 161, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "Untitled\n", "\n", "\n", "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "page = document(400, 120, 'pt').addpage()\n", "pen1 = shape().nostroke().fill(rgba(255, 0, 255, 170))\n", "pen = shape().nostroke().fill(rgba(255, 0, 0, 120))\n", "factor1 = 110 / f.density\n", "factor = 50 / f.density\n", "cmds = []\n", "page.place(pen.path(mod_plist.to_path().scale(factor).translate(0, 90)))\n", "page.place(pen1.path(mod_plist1.to_path().scale(factor1).translate(0, 90)))\n", "show(page)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## " ] }, { "cell_type": "code", "execution_count": 159, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "Untitled\n", "\n", "\n", "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "page = document(400, 120, 'pt').addpage()\n", "pen1 = shape().nostroke().fill(rgba(255, 0, 0, 255))\n", "pen = shape().nostroke().fill(rgba(255, 0, 0, 255))\n", "factor1 = 150 / f.density\n", "factor = 90 / f.density\n", "cmds = []\n", "page.place(pen.path(mod_plist.to_path().scale(factor).translate(0, 90)))\n", "page.place(pen1.path(mod_plist1.to_path().scale(factor1).translate(0, 90)))\n", "show(page)" ] }, { "cell_type": "code", "execution_count": 156, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "Untitled\n", "\n", "\n", "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "page = document(400, 120, 'pt').addpage()\n", "pen1 = shape().nostroke().fill(rgba(255, 0, 255, 170))\n", "pen = shape().nostroke().fill(rgba(255, 0, 255, 80))\n", "factor1 = 90 / f.density\n", "factor = 45 / f.density\n", "cmds = []\n", "page.place(pen.path(mod_plist.to_path().scale(factor).translate(0, 70)))\n", "page.place(pen1.path(mod_plist1.to_path().scale(factor1).translate(0, 70)))\n", "show(page)" ] }, { "cell_type": "code", "execution_count": 76, "metadata": {}, "outputs": [], "source": [ "def stretch_char(f, ch, height=-0.33):\n", " path_orig = glyphcommands(f, ch)\n", " path_cmds = []\n", " mid_y = f.ascender * height\n", " for cmd in path_orig:\n", " if hasattr(cmd, 'y') and cmd.y < mid_y:\n", " path_cmds.append(nudge(cmd, x=-355, y=0))\n", " else:\n", " path_cmds.append(cmd)\n", " path_mod = Path(path_cmds)\n", " return path_mod" ] }, { "cell_type": "code", "execution_count": 151, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "Untitled\n", "\n", "\n", "\n", "\n", "\n", "\n", "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "page = document(400, 120, 'pt').addpage()\n", "pen1 = shape().nostroke().fill(rgba(255, 0, 255, 170))\n", "pen = shape().nostroke().fill(rgba(255, 0, 0, 80))\n", "factor1 = 80 / f.density\n", "factor = 80 / f.density\n", "for ch in M:\n", " glyph_path = stretch_char(f, ch, uniform(-1, -0.25)).scale(factor).translate(cx, 90)\n", " page.place(pen.path(glyph_path))\n", " cx += advancefor(f, ch) * factor\n", "show(page)\n" ] }, { "cell_type": "code", "execution_count": 78, "metadata": {}, "outputs": [], "source": [ "def stretch_char(f, ch, height=-0.33):\n", " path_orig = glyphcommands(f, ch)\n", " path_cmds = []\n", " mid_y = f.ascender * height\n", " for cmd in path_orig:\n", " if hasattr(cmd, 'y') and cmd.y < mid_y:\n", " path_cmds.append(nudge(cmd, x=-700, y=20))\n", " else:\n", " path_cmds.append(cmd)\n", " path_mod = Path(path_cmds)\n", " return path_mod" ] }, { "cell_type": "code", "execution_count": 79, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "Untitled\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "page = document(400, 290, 'pt').addpage()\n", "pen1 = shape().nostroke().fill(rgba(255, 0, 255, 170))\n", "pen = shape().nostroke().fill(rgba(255, 0, 0, 80))\n", "factor1 = 10 / f.density\n", "factor = 80 / f.density\n", "cx = 20\n", "for ch in M:\n", " glyph_path = stretch_char(f, ch, uniform(-1, -0.25)).scale(factor).translate(cx, 90)\n", " glyph_path1 = stretch_char(f, ch, uniform(-1, -0.25)).scale(factor).translate(cx, 90)\n", " page.place(pen.path(glyph_path))\n", " page.place(pen1.path(glyph_path1))\n", " cx += advancefor(f, ch) * factor\n", " cx += advancefor(f1, ch) * factor1\n", "show(page)\n" ] }, { "cell_type": "code", "execution_count": 80, "metadata": {}, "outputs": [], "source": [ "qf_path_orig = combine_path(f, \"Memory\")\n", "qf_plist = qf_path_orig.to_polyline_list(samples_per=14)\n", "qf_path_orig = combine_path(f1, \" ן ו ר כ י ז\")\n", "qf_plist1 = qf_path_orig.to_polyline_list(samples_per=14)" ] }, { "cell_type": "code", "execution_count": 81, "metadata": {}, "outputs": [], "source": [ "mid_x = f.ascender * -0.33\n", "mid_x = f1.ascender * -0.33\n", "mod = []\n", "# for pline in qf_plist1:\n", "# verts = []\n", "# # iterate through each vertex\n", "# for item in pline.vertices:\n", "# # get x and y coordinate\n", "# new_x, new_y = item[0], item[1]\n", "# # modify y coordinate if less than a certain threshold\n", "# if item[1] < mid_x:\n", "# verts.append([new_x -300, new_y ])\n", "# else:\n", "# verts.append([new_x, new_y]) \n", "# for pline in qf_plist:\n", "# verts = []\n", "# # iterate through each vertex\n", "# for item in pline.vertices:\n", "# # get x and y coordinate\n", "# new_x, new_y = item[0], item[1]\n", "# # modify y coordinate if less than a certain threshold\n", "# if item[1] < mid_x:\n", "# verts.append([new_x + 300, new_y ])\n", "# else:\n", "# verts.append([new_x, new_y]) " ] }, { "cell_type": "code", "execution_count": 150, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "Untitled\n", "\n", "\n", "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "page = document(190, 80).addpage()\n", "pen1 = shape().nostroke().fill(rgba(255, 0, 255, 170))\n", "pen = shape().nostroke().fill(rgba(255, 0, 0, 80))\n", "factor1 = 45 / f.density\n", "factor = 22 / f.density\n", "cmds = []\n", "page.place(pen1.path(mod_plist1.to_path().scale(factor1).translate(20, 35)))\n", "page.place(pen.path(mod_plist.to_path().scale(factor).translate(20, 35)))\n", "show(page)" ] }, { "cell_type": "code", "execution_count": 83, "metadata": {}, "outputs": [], "source": [ "qf_path_orig = combine_path(f, \"Memory\")\n", "qf_plist = qf_path_orig.to_polyline_list(samples_per=14)\n", "qf_path_orig = combine_path(f1, \" ן ו ר כ י ז\")\n", "qf_plist1 = qf_path_orig.to_polyline_list(samples_per=20)" ] }, { "cell_type": "code", "execution_count": 84, "metadata": {}, "outputs": [], "source": [ "mid_x = f1.ascender * -0.33\n", "mid_x = f.ascender * -0.33\n", "mod = []\n", "for pline in qf_plist1:\n", " verts = []\n", " for item in pline.vertices:\n", " # get x and y coordinate\n", " new_x, new_y = item[0], item[1]\n", " # modify y coordinate if less than a certain threshold\n", " if item[1] < mid_x:\n", " verts.append([new_x+700, new_y ])\n", " else:\n", " verts.append([new_x, new_y])\n", "for pline in qf_plist1:\n", " verts = []\n", " for item in pline.vertices:\n", " # get x and y coordinate\n", " new_x, new_y = item[0], item[1]\n", " # modify y coordinate if less than a certain threshold\n", " if item[1] < mid_x:\n", " verts.append([new_x-200, new_y ])\n", " else:\n", " verts.append([new_x, new_y])" ] }, { "cell_type": "code", "execution_count": 144, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "Untitled\n", "\n", "\n", "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "page = document(400, 120, 'pt').addpage()\n", "pen = shape().nostroke().fill(rgba(255, 0, 0, 120))\n", "factor1 = 110 / f.density\n", "pen1 = shape().nostroke().fill(rgba(255, 0, 255, 170))\n", "factor = 50 / f.density\n", "cmds = []\n", "page.place(pen.path(mod_plist.to_path().scale(factor).translate(20, 90)))\n", "page.place(pen1.path(mod_plist1.to_path().scale(factor1).translate(20, 90)))\n", "show(page)" ] }, { "cell_type": "code", "execution_count": 86, "metadata": {}, "outputs": [], "source": [ "mod = []\n", "for pline in qf_plist:\n", " verts = []\n", " for item in pline.vertices:\n", " verts.append([item[0] + np.sin(item[1] * 0.01)*20,\n", " item[1] + np.cos(item[0] * 0.01) * 20])\n", " new_pline = Polyline(verts)\n", " mod.append(new_pline)\n", "mod_plist = PolylineList(mod)" ] }, { "cell_type": "code", "execution_count": 87, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "Untitled\n", "\n", "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "page = document(400, 90, 'pt').addpage()\n", "pen = shape().nostroke().fill(rgba(255, 0, 0, 120))\n", "factor = 72 / f.density\n", "cmds = []\n", "page.place(pen.path(mod_plist.to_path().scale(factor).translate(0, 90)))\n", "show(page)\n" ] }, { "cell_type": "code", "execution_count": 133, "metadata": {}, "outputs": [], "source": [ "qf_path_orig = combine_path(f, \"Memory\")\n", "qf_plist = qf_path_orig.to_polyline_list(samples_per=14)\n", "qf_path_orig = combine_path(f1, \" ן ו ר כ י ז\")\n", "qf_plist1 = qf_path_orig.to_polyline_list(samples_per=20)" ] }, { "cell_type": "code", "execution_count": 134, "metadata": {}, "outputs": [], "source": [ "mod = []\n", "for pline in qf_plist:\n", " verts = []\n", " for item in pline.vertices:\n", " new_x, new_y = item[0], item[1]\n", " if item[1] < mid_x:\n", " verts.append([new_x +200, new_y])\n", " else:\n", " verts.append([new_x, new_y])\n", " new_pline = Polyline(verts)\n", " mod.append(new_pline)\n", "mod_plist = PolylineList(mod)\n", "mod = []\n", "for pline in qf_plist1:\n", " verts = []\n", " for item in pline.vertices:\n", " new_x, new_y = item[0], item[1]\n", " if item[1] < mid_x:\n", " verts.append([new_x -180, new_y])\n", " else:\n", " verts.append([new_x, new_y])\n", " new_pline = Polyline(verts)\n", " mod.append(new_pline)\n", "mod_plist1 = PolylineList(mod)" ] }, { "cell_type": "code", "execution_count": 139, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "Untitled\n", "\n", "\n", "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "page = document(400, 120, 'pt').addpage()\n", "pen = shape().nostroke().fill(rgba(255, 0, 255, 170))\n", "pen1 = shape().nostroke().fill(rgba(255, 0, 0, 150))\n", "factor1 = 130 / f.density\n", "factor = 59 / f.density\n", "cmds = []\n", "page.place(pen.path(mod_plist.to_path().scale(factor).translate(0, 70)))\n", "page.place(pen1.path(mod_plist1.to_path().scale(factor1).translate(0, 70)))\n", "show(page)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.5" } }, "nbformat": 4, "nbformat_minor": 4 }