Navigation Menu

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 / Aqui_SP-OSMNX.py
Created August 25, 2023 13:30
Experimentos com osmnx
import pickle
from pathlib import Path
import osmnx as ox
from download_from_gdrive import download_from_gdrive
# configure the place, network type, trip times, and travel speed
place = {"city": "São Paulo", "country": "Brazil"}
network_type = "walk"
@villares
villares / pygame_jukebox_tosca.py
Last active August 19, 2023 16:16
Tocadores de arquivos mp3 com pygame
# TODO quando som termina, retomar não recomeça
# (mudar para próximo som autmaticamente?)
from pathlib import Path
import pygame
# Procura arquivos .mp3 na mesma pasta
folder = Path.cwd() # se quiser pode trocar por Path('/caminho/pasta/')
audio_files = [fp for fp in sorted(folder.iterdir())
if fp.name.lower().endswith('.mp3')]
@villares
villares / export_single_png.py
Created August 18, 2023 14:24
Export PNG with transparent background
# using py5 imported mode (https://py5coding.org to learn more)
def setup():
size(600, 600) # drawing size
output_canvas = create_graphics(width, height)
background(255, 0, 0) # you can turn this off, this won't be recorded!
begin_record(output_canvas) # starts recording
# output_canvas.clear() # clears pixels (not necessary in this case)
color_mode(HSB) # this needs to be inside the recording!
no_stroke() # same as with the color_mode, has to be brought here
@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 / py_lotusrosettes.pyde
Last active July 2, 2023 11:38
Lotus Rosettes for Processing Python Mode
"""
Under Creative Commons License
https:#creativecommons.org/licenses/by-sa/4.0/
Ported for Processing Python Mode py.processing.org <- for Processing IDE
by Alexandre Villares abav.lugaralgum.com, 9-Oct-2018
Based upon code for p5js.org at https://jcponce.github.io/misc/lotusrosettes.html
by Juan Carlos Ponce Campuzano, 9-Oct-2018
Based upon Dan Anderson's code
https:#www.openprocessing.org/sketch/519299
"""
@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 / kirigami.pyde
Last active May 24, 2023 14:41
There are several files on this Gist... the ones ending in `.pyde` are for Processing Python Mode, the others `.py` are for use with the https://py5coding.org library on Python 3.8+. One has a "manual" tuples option.
# for Processing Python Mode
# https://abav.lugaralgum.com/como-instalar-o-processing-modo-python/index-EN.html
add_library('pdf') # equivale a importar a lib de PDF no Processing
mode_3D = True # modo 3D ou 2D (muda com tecla '3')
save_pdf = False # Avisa que vai exportar, tecla 's'
seed = 5465 # "semente" que trava os sorteios dos números aleatórios e do noise
s = 0.005 # noise scale
@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():