Skip to content

Instantly share code, notes, and snippets.

@petrblahos
petrblahos / draw_text_on_a_font.py
Created January 3, 2024 19:21
Draw a text on a text outline.
from collections import defaultdict
import math
import sys
import time
import bezier
import pygame
import numpy as np
from fontTools.pens.basePen import (BasePen, )
@petrblahos
petrblahos / bezier_animation.py
Created December 22, 2023 10:03
Animate a point over a list of bezier curves
import bezier
import pygame
class BezierLoop:
WIDTH = 400
HEIGHT = 400
def prepare_window(self):
self.screen = pygame.display.set_mode((self.WIDTH, self.HEIGHT))
self.screen.fill((0, 0, 0))
@petrblahos
petrblahos / pgm_ttf_effect_bubble.py
Created December 15, 2023 13:41
A bubble effect under a writing.
from collections import defaultdict
import io
import random
import pygame
from fontTools.pens.svgPathPen import (SVGPathPen, )
from fontTools.ttLib import TTFont
@petrblahos
petrblahos / starfield.py
Created December 15, 2023 11:01
Starfield-like effect
import math
import random
import pygame
class Star(pygame.sprite.Sprite):
def __init__(self, center, r, angle):
super().__init__()
self.center = center
self.angle = angle
@petrblahos
petrblahos / particle_c_growing_01.py
Created December 15, 2023 10:04
Simple particles in pygame
import math
import random
import pygame
class Particle(pygame.sprite.Sprite):
def __init__(self, x, y):
super().__init__()
self.start = (x, y)
self.x = x
@petrblahos
petrblahos / font_svg_pygame.py
Last active November 11, 2023 16:14
Draw glyphs on a pygame surface using fonttools and SVG.
from collections import defaultdict
import io
import sys
import numpy as np
from scipy.special import comb
import pygame
from fontTools.pens.svgPathPen import (SVGPathPen, )
from fontTools.pens.basePen import (BasePen, )
@petrblahos
petrblahos / ttf_font_kerning.py
Created October 21, 2023 10:43
Drawing text with a font, using kerning info.
from collections import defaultdict
import wx
from fontTools.pens.wxPen import WxPen
from fontTools.ttLib import TTFont
class MyFrame(wx.Frame):
def __init__(self, ttfont: TTFont):
wx.Frame.__init__(self, None, -1, "Font painter")
self.font = ttfont
@petrblahos
petrblahos / draw_ttf_unicodes.py
Created October 19, 2023 12:59
Drawing more characters from a ttf font.
import wx
from fontTools.pens.wxPen import WxPen
from fontTools.ttLib import TTFont
class MyFrame(wx.Frame):
def __init__(self, ttfont: TTFont):
wx.Frame.__init__(self, None, -1, "Font painter")
self.font = ttfont
self.Bind(wx.EVT_PAINT, self.on_paint)
@petrblahos
petrblahos / draw_ttf_character.py
Created October 19, 2023 12:01
Draw a character from a ttf font using fonttools / pen.
import wx
from fontTools.pens.wxPen import WxPen
from fontTools.ttLib import TTFont
class MyFrame(wx.Frame):
def __init__(self, ttfont: TTFont):
wx.Frame.__init__(self, None, -1, "Font painter")
self.font = ttfont
self.Bind(wx.EVT_PAINT, self.on_paint)
import sys
import cv2
import numpy as np
def main(fn):
SZ = 21
OUTPUT_ARRAY = [[0]*SZ for i in range(SZ)]
img = cv2.imread(fn)