Skip to content

Instantly share code, notes, and snippets.

import re
def filter_fonts(df, regex_filters):
df_new = pd.concat([df.filter(regex=re.compile(regex, re.IGNORECASE), axis=1).sum(axis=1).astype(bool) for regex in regex_filters], axis=1)
mask = df_new.all(axis=1)
return list(df.loc[mask].family)
filtered_fontnames = filter_fonts(df, ['Black', 'cyrillic', '_serif'])
filtered_fontnames
import glob
# change the root directory according to your setup
ROOT = '../../input/fonts/ofl'
# some fonts are within /ofl/fontname/static directory (2 levels deep)
all_fonts_path = glob.glob(ROOT + '/**/**/*.ttf', recursive=True)
print('number of font files in total: ', len(all_fonts_path))
def filter_fonts_get_paths(df, root='./', variants=['_'], subsets=['_'], category=''):
# exceptions
if not variants or variants == [''] or variants == '': variants = ['_']
if not subsets or subsets == [''] or subsets == '': subsets = ['_']
# apply filters
regex_filters = variants + subsets + ['_'+category]
df_new = pd.concat([df.filter(regex=re.compile(regex, re.IGNORECASE), axis=1).sum(axis=1).astype(bool) for regex in regex_filters], axis=1)
mask = df_new.all(axis=1)
filtered_fontnames = list(df.loc[mask].family)
import random
IMG_HEIGHT = 512
IMG_WIDTH = 512
paths = filter_fonts_get_paths(df, root=ROOT, subsets=[''], variants=['bold'], category='')
r = random.randrange(0, len(paths))
# sample text and font
text = "G"
from IPython.display import clear_output
# display images
monitor = False
# font filtering
df = pd.read_csv('./google-fonts-annotaion.csv')
paths = filter_fonts_get_paths(df, root=ROOT, subsets=['latin'], variants=['bold'], category='serif')
# text setup
@erraticgenerator
erraticgenerator / p5js-mp4-export-2.html
Created December 5, 2020 22:19
Video export from p5.js sketch 2 (draw loop)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="https://unpkg.com/h264-mp4-encoder/embuild/dist/h264-mp4-encoder.web.js"></script>
<script src="https://cdn.jsdelivr.net/npm/p5@1.1.9/lib/p5.js"></script>
</head>
@erraticgenerator
erraticgenerator / p5-textToPoints-1.html
Created December 6, 2020 18:58
1. basic use of p5.Font.textToPoints()
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="https://cdn.jsdelivr.net/npm/p5@1.1.9/lib/p5.js"></script>
</head>
@erraticgenerator
erraticgenerator / p5-textToPoints-2.html
Created December 6, 2020 19:36
2. individual letters with 2d array
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="https://cdn.jsdelivr.net/npm/p5@1.1.9/lib/p5.js"></script>
</head>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="https://cdn.jsdelivr.net/npm/p5@1.1.9/lib/p5.js"></script>
<script src="https://cdn.jsdelivr.net/npm/opentype.js@latest/dist/opentype.min.js"></script>
</head>
function setup() {
createCanvas(800, 400)
background(0)
const str = 'Hello, world! Hi, there! Nice to meet you!'
const wordsStr = str.split(' ')
textSize(48)
// track word position