Skip to content

Instantly share code, notes, and snippets.

View villares's full-sized avatar
💥

Alexandre B A Villares villares

💥
View GitHub Profile
@villares
villares / mp4_to_gif.py
Last active July 31, 2023 06:26
A bare bones mp4 to gif converter Python CLI script
#! /home/villares/thonny-python-env/bin/python3
"""
MP4 to GIF animation. Depends on moviepy and ffmpeg.
"""
import argparse
from moviepy.editor import *
parser = argparse.ArgumentParser(prog='Create a GIF animation from a MP4 file. Depends on moviepy and ffmpeg.')
parser.add_argument('-i', '--input', help='Input .mp4 file.')
@villares
villares / image_pickle_concept.py
Last active July 29, 2023 04:43
monkey patching a Py5Image to allow pickling
import pickle
import py5
from py5 import Py5Image
old_new = Py5Image.__new__
def new_new(self, *args):
if args:
return old_new(self, *args)
@villares
villares / a.svg
Created July 15, 2023 22:27
SVG File that breaks Processing 4.2 parsing
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@villares
villares / stecil-generator-tabajara.py
Created June 16, 2023 19:30
Gerador de estêncil (desenhe linhas interrompidas com o mouse)
import py5
from shapely.geometry import Polygon, MultiPolygon, GeometryCollection, LineString, Point
from shapely.ops import unary_union
MIN_GAP = 10
MIN_LT = 5 # minimum line thickness
SVG_SUFIX = 'output.svg'
save_svg = False
line_thickness = 10
@villares
villares / conwaysGOL_py5_numpy.py
Last active May 19, 2023 14:17
GOL with numpy & scipy convolve2d
# based on https://www.jpytr.com/post/game_of_life/
# previous version calculated neighbours twice at each step... it could be useful to color cells but I removed it.
import py5
import numpy as np
from scipy.signal import convolve2d
board_img = None
def setup():
#!/usr/bin/env python
"""
Demo Thumbnail Grid Image Viewer
Displays image files from a folder.
Based on https://github.com/PySimpleGUI/PySimpleGUI/blob/master/DemoPrograms/Demo_PNG_Thumbnail_Viewer.py
"""
from pathlib import Path
import io
@villares
villares / download_images_modify_files.py
Last active November 13, 2023 00:10
Backup HackMD.io Notes
"""
Downloads images from my notes at HackMD.io.
Creates new MD files with relative path image links.
Uses the links from the 'notes-backup' files downloaded with
download_notes.py (run it first)
I was skipping images hosted from my dreamhost account
but decided to download them too.
"""
@villares
villares / svgtoshapes.py
Created April 27, 2023 18:10 — forked from un1tz3r0/svgtoshapes.py
shapely svg import
''' Read and parse SVG files returning a shapely GeometryCollection containing the paths and primitives found.
Transforms are applied and all shapes are returned in the SVG root elements coordinate space. Primitives (rect,
circle and ellipse) are converted to equivalent paths, and only shape outlines are rendered, stroke properties
have no affect and are discarded.
Curved paths (arc and bezier commands and rounded rect, ellipse and circle elements) are linearized using a
naive approach that attempts to create enough segments to reduce maximum distance to the curve to below a
certain threshold, although this is probably not very efficient and most likely implemented in a fairly
broken way.'''
@villares
villares / svg_display_psg_cairosvg.py
Last active April 27, 2023 20:47
Showing SVG with PySimpleGUI
from io import BytesIO
import PySimpleGUI as sg
import cairosvg
# This didn't work with the example file in this gist (the raster background didn't show up)
svg_content = '<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100"><rect x="10" y="10" width="80" height="80"/></svg>'
# filename = 'NdPAbril2.svg'
# with open(filename, 'r') as f:
# svg_content = f.read()
@villares
villares / PCD2022.md
Created January 24, 2023 22:28
Processing Community Day Brasil 2022 oficina Introdução à programação criativa com Python