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 / processing_gcode_generator.pde
Last active May 8, 2023 22:53 — forked from berinhard/processing_gcode_generator.pde
Simple processing Sketch to generate .gcode files for all SVGs in a directory
/*
This sketch is an adaptation from Sighack's Gcode Export
Blog post: https://sighack.com/post/processing-boilerplate-with-gcode-export
Depends on http://www.ricardmarxer.com/geomerative/
TODO:
[ ] Select directory dialog
[ ] Check file extension
#!/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 / 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 / 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 / PCD2022.md
Created January 24, 2023 22:28
Processing Community Day Brasil 2022 oficina Introdução à programação criativa com Python
# You need to install py5 (py5coding.org) and use "imported mode" feeding this code to run_sketch.py
# Learn more at https://abav.lugaralgum.com/como-instalar-py5/index-EN.html
def setup():
global seed
size(800, 300, P3D)
frame_rate(10)
seed = 26876 # novaSemente()
import cv2
from PIL import Image
import numpy as np
import PySimpleGUI as sg
"""
Interesting program that shows your webcam's image as ASCII text. Runs in realtime, producing a stream of
images so that it is actually animated ASCII text. Wild stuff that came about from a post on Reddit of all
places. The software bits that turn the image into ASCII text were shamelessly taken from this gist:
https://gist.github.com/cdiener/10491632
import py5
import PySimpleGUI as sg
bg = True
values = {'-Text-': '', '-Hue-': 0, '-BG-': False}
def setup():
global window
py5.size(600, 600)
py5.color_mode(py5.HSB)
@villares
villares / dict_csv.py
Last active November 10, 2022 21:34
JSON IBGE / CSV
import csv
from urllib.request import Request, urlopen
# I used the publish feature from a Google Spreadsheet
url = "https://docs.google.com/spreadsheets/d/e/2PACX-1vT7etkg--Axh_CJlmZdlJ3rrE71rZ10kNQpbqUr8rcPL8WLNepgaIJMN6ZbUHbscjBv014rjaB9Qkwy/pub?gid=0&single=true&output=csv" # change to your own!
response = urlopen(Request(url))
content = response.read().decode('utf-8')
data = csv.DictReader(content.splitlines())
cols = data.fieldnames
@villares
villares / image_helper.py
Created November 8, 2022 21:44
for use with PySimpleGUI
import PIL.Image
import io
def image_as_png_bytes(file_path, resize=None):
"""
Open an image file and convert it into PNG formated bytes, resize optional.
Return tuple (bytes, <dict from PIL.Image.info>)
"""
img = PIL.Image.open(file_path)