Skip to content

Instantly share code, notes, and snippets.

from PIL import Image
import os
def crop_image_to_square(img_path, output_path):
with Image.open(img_path) as img:
width, height = img.size
size = min(width, height)
left = (width - size) / 2
top = (height - size) / 2
@tabreturn
tabreturn / clean_gamelist.xml.py
Created October 8, 2023 05:58
emulationstation remove game elements without an image element
import xml.etree.ElementTree as ET
import os
# rename the input xml file to gamelist~.xml
if os.path.exists('gamelist.xml'):
os.rename('gamelist.xml', 'gamelist~.xml')
# parse the input xml file (now gamelist~.xml)
tree = ET.parse('gamelist~.xml')
root = tree.getroot()
@tabreturn
tabreturn / amoeba.py
Created September 6, 2022 08:44
py5_modules
# add these two lines to the top of any imported module
from py5 import *
cs = get_current_sketch()
class Amoeba():
def __init__(self, x, y):
self.location = Py5Vector(x, y)
def display(self):
@tabreturn
tabreturn / amoeba.py
Created September 6, 2022 08:44
py5_modules
# add these two lines to the top of any imported module
from py5 import *
cs = get_current_sketch()
class Amoeba():
def __init__(self, x, y):
self.location = Py5Vector(x, y)
def display(self):
@tabreturn
tabreturn / dungeon.js
Last active March 26, 2021 06:56
a-frame dungeon demo
/*
TO BEGIN:
1. download the web xr emulator plugin for firefox/chrome:
* https://addons.mozilla.org/en-US/firefox/addon/webxr-api-emulator/
* https://chrome.google.com/webstore/detail/webxr-api-emulator/
mjddjgeghkdijejnciaefnkjmkafnnje
2. run an https web server using servez: https://greggman.github.io/servez/
@tabreturn
tabreturn / genetic.pyde
Last active February 27, 2022 23:19
genetic algorithm sketch
'''
processing.py sketch based on:
https://natureofcode.com/book/chapter-9-the-evolution-of-code/
'''
#1. TEST OUT STRING MODULE ###################################################
import string
print(string.ascii_letters)
print(string.ascii_letters[25])
@tabreturn
tabreturn / 0-scaffold.py
Last active January 15, 2021 03:45
- pyp5js port of microscopic sketch
# live version:
# https://editor.computiful.org/tabreturn/sketches/F6dumhqW0
class Amoeba(object):
def __init__(self, x, y):
print('amoeba initialized')
self.x = x
self.y = y
@tabreturn
tabreturn / twinstick.pyde
Created November 30, 2020 19:31
- a simple twin-stick-style control scheme for processing.py
up_pressed = False
left_pressed = False
down_pressed = False
right_pressed = False
x = 150
y = 150
speed = 5
def setup():
@tabreturn
tabreturn / mp4museum.py
Last active November 5, 2020 22:29
- adapt mp4museum to work with a presentation clicker
#!/usr/bin/python
# mp4museum.org by julius schmiedel 2019
import os
import sys
import glob
from subprocess import Popen, PIPE
import RPi.GPIO as GPIO
@tabreturn
tabreturn / handrolled_3d.pyde
Last active November 5, 2020 03:26
- handroll a 3d renderer using processing.py 2d features only
# https://en.wikipedia.org/wiki/3D_projection#Perspective_projection
from rotations import *
# pyramid coordinates
a1 = [0.0, 0.0, 50.0] # the 3D position of a point A that is to be projected
a2 = [0.0, 100.0, 50.0]
a3 = [100.0, 100.0, 50.0]
a4 = [100.0, 0.0, 50.0]
a5 = [50.0, 50.0, 125.0]