Skip to content

Instantly share code, notes, and snippets.

@bmander
bmander / center.pde
Created November 27, 2011 21:23
how to center the screen, in processing
// how to center the screen in processing. I have the hardest time remembering, much less intuiting, this:
size( 200, 200 );
int l = 0;
int b = 70;
int r = 500;
int t = 700;
float xres = width/float(r-l);
@bmander
bmander / scaletranslate.pde
Created December 31, 2011 22:29
A simple app for learning how scale() and translate() work.
// I, Brandon Martin-Anderson, release this into the public domain.
// Do whatever you want with it.
// A simple app for learning how scale() and translate() work.
// Left click and drag to scale.
// Right click and drag to translate.
// Spacebar to switch to between translate-first, and scale-first.
float xscale=1;
float yscale=1;
@bmander
bmander / prism.pde
Created January 3, 2012 08:02
draw the universe
import java.awt.event.*;
class Path {
ArrayList points;
Path() {
points = new ArrayList();
}
void add(float x, float y) {
this.points.add( new PVector( x, y ) );
@bmander
bmander / landcover.pde
Created January 5, 2012 19:52
Post-apocalyptic land cover simulator
class Landcover {
color DEVELOPED_HIGH = -5636096;
color DEVELOPED_MEDIUM = -917504;
color DEVELOPED_LOW = -2385534;
color DEVELOPED_OPEN = -2044724;
color SHRUB = -3032446;
color FOREST_EVERGREEN = -14916045;
color FOREST_MIXED = -4535151;
color FOREST_DECIDUOUS = -9721242;
color WETLAND_WOODY = -4531987;
@bmander
bmander / scrape2go.py
Created January 12, 2012 21:32
scrape car2go san diego site for vehicle locations
import urllib
import json
URL = "http://www.car2go.com/portal/sandiego/page/mybookings/mapEnlarged.faces"
KEY = "ptvMap.data = "
def grab_sandiego_vehicles():
#get site HTML
fp = urllib.urlopen( URL )
sitestr = fp.read()
@bmander
bmander / PixelBuffer.pde
Created January 27, 2012 17:41
a sample for Disco Office
class PixelBuffer {
Color[][] colors;
int width;
int height;
PixelBuffer(int width, int height) {
this.colors = new Color[width][height];
this.width=width;
this.height=height;
}
@bmander
bmander / biohazard.js
Created April 7, 2012 22:21
biohazard symbol
//print biohazard symbol, at http://fab.cba.mit.edu/classes/S62.12/people/martinanderson.brandon/solver2.html
function makecircle(r){
return function(x,y){
return Math.pow(x,2) + Math.pow(y,2) < Math.pow(r,2);
}
}
function translate(tx, ty, func){
return function(x,y){
function sqrt(a){
return Math.pow(a,0.5);
}
function sq(a){
return Math.pow(a,2);
}
function rotate(theta, func){
return function(x,y){
@bmander
bmander / happyface.js
Created April 12, 2012 19:35
happyface
function makerectangle(left,right,bottom,top){
return function(x,y){
return (x>left && x<right && y > bottom && y < top)
}
}
function makecircle(cx,cy,r){
return function(x,y){
return Math.pow(x-cx,2)+Math.pow(y-cy,2)<Math.pow(r,2)
}
@bmander
bmander / bulgespiral.js
Created April 12, 2012 19:47
bulge spiral
function translate(tx, ty, func){
return function(x,y){
var xprime = x-tx;
var yprime = y-ty;
return func(xprime,yprime);
}
}
function dist(x,y){