Skip to content

Instantly share code, notes, and snippets.

Avatar

Alexandre B A Villares villares

View GitHub Profile
View pyfirmata_helper.py
# 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 serial.tools.list_ports.comports(),
if one port is found, tries that one. If more than one port is found,
@villares
villares / more_tkinter_colors.py
Created Jul 20, 2022
Copy tkinter color names to clipboard using pyperclip...
View more_tkinter_colors.py
from tkinter import *
import pyperclip
MAX_ROWS = 36
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
villares / pinball_pymunk_py5.py
Last active Jun 19, 2022
Made with @Introscopia and 2D simulations course at participants at Sesc Av. Paulista [WIP at https://github.com/villares/pymunk-pinball-paulista/]
View pinball_pymunk_py5.py
# Check out further developments at: https://github.com/villares/pymunk-pinball-paulista/
# Pymunk PINBALL experiments at Sesc Av. Paulista
# Needs py5.ixora.io and pymunk.org
# 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
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 `py5.ixora.io` library on Python 3.8+. One has a "manual" tuples option.
View kirigami.pyde
# 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 / image_viewer.py
Last active May 31, 2022
Tweaking a PySimpleGUI Image viewer example
View image_viewer.py
# 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 https://gorillasun.de/blog/an-algorithm-for-irregular-grids#bool
# via Chris Barber https://twitter.com/code_rgb/status/1528042828219179008
# Code for Processing Python mode (py.processing.org)
from collections import namedtuple
from random import choice, sample, seed
Rect = namedtuple("Rect", "posX posY dimX dimY")
rect_infos = []
View sketch_2021_04_22.py
"""
Inspired by 'follow 3' code from Keith Peters in the Processing examples
you will need http://py5.pixora.io's sketch runner for imported mode
"""
def setup():
global first_seg, other_seg
size(500, 500)
stroke_weight(9)
color_mode(HSB)
View sketch_2021_04_21.py
# you will need http://py5.pixora.io's sketch runner for imported mode
def setup():
global first_seg
size(500, 500)
stroke_weight(9)
color_mode(HSB)
seg = Segment((100, 100), (100, 100))
for _ in range(10):
seg = Segment((100, 100), (100,100), seg)
@villares
villares / other_soft_processing_imported_py5.py
Last active Apr 7, 2022
Noite de Processing - Simulações Físicas - com John e Alexandre https://www.youtube.com/watch?v=5u49PR9ICMg
View other_soft_processing_imported_py5.py
# You'll need py5 -https://py5.ixora.io
# Also needs http://pymunk.org
# 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
villares / rotated_rect.pyde
Last active Feb 27, 2022
Rotated Rectangle example
View rotated_rect.pyde
from random import choice
add_library('geomerative')
def setup():
size(500, 500)
RG.init(this)
noLoop()
def draw():
background(200)