Skip to content

Instantly share code, notes, and snippets.

Avatar

Alexandre B A Villares villares

View GitHub Profile
@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 / 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 / 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 / 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)
@villares
villares / pvector_for_py5.py
Last active Nov 1, 2021
A quick proof of concept, PVector-like class for use with my py5 sketches
View pvector_for_py5.py
# A quick proof of concept, PVector-like class for use with my py5 (http://py5.ixora.io) based sketches
# Made from previous versions for pyp5js: https://gist.github.com/villares/5c476cbc44c1153fed159eae36fc016b
import math
from numbers import Number
TWO_PI = math.tau
class PVector:
View chain_reaction.pyde
from random import choice
atoms = [] # lista de objetos
neutrons = []
def setup():
""" Define área de desenho e popula lista de particles """
size(800, 800) # área de desenho (width, height)
half_width, half_height = width / 2, height / 2
density = 200 # try 900