Skip to content

Instantly share code, notes, and snippets.


Alexandre B A Villares villares

View GitHub Profile
# I'm counting now on a JPype enviroment provided by importing py5 (so I can use javax.swing pane)
# see the previous revision if you don't want that!
def get_arduino(port=None):
This is a PyFirmata 'helper' that tries to connect to an Arduino
compatible board.
If no port is informed, using pyserial's,
if one port is found, tries that one. If more than one port is found,
villares /
Created Jul 20, 2022
Copy tkinter color names to clipboard using pyperclip...
from tkinter import *
import pyperclip
FONT_SIZE = 10 # (pixels)
COLORS = ['snow', 'ghost white', 'white smoke', 'gainsboro', 'floral white', 'old lace',
'linen', 'antique white', 'papaya whip', 'blanched almond', 'bisque', 'peach puff',
'navajo white', 'lemon chiffon', 'mint cream', 'azure', 'alice blue', 'lavender',
'lavender blush', 'misty rose', 'dark slate gray', 'dim gray', 'slate gray',
villares /
Last active Jun 19, 2022
Made with @Introscopia and 2D simulations course at participants at Sesc Av. Paulista [WIP at]
# Check out further developments at:
# Pymunk PINBALL experiments at Sesc Av. Paulista
# Needs and
# You'll need to learn about py5 imported mode (sketch_runner)
import pymunk as pm # importa lib de simulação
from random import choice
space = pm.Space() # objeto espaço de simulação
villares / kirigami.pyde
Last active Jun 8, 2022
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 `` library on Python 3.8+. One has a "manual" tuples option.
View kirigami.pyde
# for Processing Python Mode
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 /
Last active May 31, 2022
Tweaking a PySimpleGUI Image viewer example
# For use with /home/villares/GitHub/sketch-a-day/2022/sketch_2022_05_29
import PySimpleGUI as sg
# import PySimpleGUIQt as sg
import os.path
import PIL.Image
import io
Based on: Demo for displaying any format of image file.
View irregular_grid.pyde
# Based on Ahmad Moussa's article
# via Chris Barber
# Code for Processing Python mode (
from collections import namedtuple
from random import choice, sample, seed
Rect = namedtuple("Rect", "posX posY dimX dimY")
rect_infos = []
Inspired by 'follow 3' code from Keith Peters in the Processing examples
you will need's sketch runner for imported mode
def setup():
global first_seg, other_seg
size(500, 500)
# you will need's sketch runner for imported mode
def setup():
global first_seg
size(500, 500)
seg = Segment((100, 100), (100, 100))
for _ in range(10):
seg = Segment((100, 100), (100,100), seg)
villares /
Last active Apr 7, 2022
Noite de Processing - Simulações Físicas - com John e Alexandre
# You'll need py5 -
# Also needs
# Similar to the previous one but with some monkey patching and changes the softbody grid construction
import py5
import pymunk as pm
space = pm.Space()
space.gravity = (0, 600)
villares / rotated_rect.pyde
Last active Feb 27, 2022
Rotated Rectangle example
View rotated_rect.pyde
from random import choice
def setup():
size(500, 500)
def draw():