Skip to content

Instantly share code, notes, and snippets.

@shiffman
shiffman / trigger_events_millis.pde
Created November 24, 2013 02:06
Triggering events based on time.
int state = 0;
int time1 = 2000;
int time2 = 5000;
void setup() {
}
void draw() {
@shiffman
shiffman / ImageToPrinter.pde
Last active December 30, 2015 05:19
printing an image from Processing
import java.io.FileInputStream;
import java.io.IOException;
import javax.print.Doc;
import javax.print.DocFlavor;
import javax.print.DocPrintJob;
import javax.print.PrintException;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.SimpleDoc;
@shiffman
shiffman / traditional_cartesian.pde
Created December 9, 2013 03:24
translate and scale to set origin at center and flip y-axis
void setup() {
size(400, 400);
}
void draw() {
background(0);
translate(width/2, height/2);
scale(1, -1);
// Trilateration
// from: http://en.wikipedia.org/wiki/Trilateration
// Daniel Shiffman <http://www.shiffman.net>
// April 2006
// Updating for Processing 2.1, Jan 2014
PVector p1,p2,p3;
float d1,d2,d3;
PVector it;
// Perlin Noise Blob
// Polar to Cartesian Coordinates
// Daniel Shiffman
// Nature of Code, Spring 2014
float yoff = 0.0;
void setup() {
size(640,360);
}
function setup() {
}
/*
[ {
"name": "Morgan",
"age": "30",
"location": "Boston",
"desire": "Singing",
"fear": "Violence"
},
{
"name": "Joss",
@shiffman
shiffman / everyNframes.pde
Created September 11, 2014 02:04
every N frames
color c = color(0);
void setup() {
size(200, 200);
}
void draw() {
background(c);
// % is the remainder http://processing.org/reference/modulo.html
@shiffman
shiffman / checkerboard.pde
Created September 26, 2014 16:46
Checkerboard Pattern
void setup () {
size (400, 400);
}
void draw () {
background (0);
int spacing = 10;
noStroke();
int cols = width / spacing;
int rows = height / spacing;
@shiffman
shiffman / 00_anonymous.js
Last active September 28, 2015 17:41
Discussion of issues around callbacks for multiple elements in a loop. Using setTimeout() here for demonstration purposes. Actual scenario relates to examples here: https://github.com/shiffman/Programming-from-A-to-Z-F14/tree/master/week6_apis
// While this seems like the right idea
// This does not work at all!
// The loop will finish and i will be at 10 by
// the time the anonymous function is called
for (var i = 0; i < 100; i++) {
setTimeout(function() {
console.log(i);
}, 100*i);