Skip to content

Instantly share code, notes, and snippets.

@shiffman
shiffman / gist:1341056
Created November 5, 2011 03:20
Java Objects to JSON Arrays
java.awt.Rectangle r = new java.awt.Rectangle(50,60,100,150);
JSONArray ja1 = new JSONArray();
ja1.put(r);
System.out.println(ja1.toString());
// ["java.awt.Rectangle[x=50,y=60,width=100,height=150]"]
float[] stuff = {1.0f,2.0f,3.0f,5.0f};
JSONArray ja2 = new JSONArray();
ja2.put(stuff);
@shiffman
shiffman / gist:3836206
Created October 4, 2012 20:26
PVector regex
[source,java]
----
// I do not want to match this instance of PVector.
----
I want to match this instance of PVector.
[source,java]
----
@shiffman
shiffman / gist:4146422
Created November 26, 2012 03:09
HTML for different page numbering for front matter vs content
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>The Nature of Code</title>
<style type="text/css">
div#frontmatter {
page: frontmatter;
}
// team 1 counter reaches 100, then:
if (!cannonLplaying) {
if (!MPE || ID == 0) {
cannonL.play();
cannonLplaying = true;
println("cannonLplaying");
// Game Over Overlay: THIS IS NOT LOADING
}
} else if (cannonL.time() > 6) {
@shiffman
shiffman / ProcessingLive.md
Last active December 20, 2015 13:38
Signup for "Processing Live" test broadcast.

Last week I tested broadcasting live from my office and answering questions about Processing via google hangout. You can watch an archive of the broadcast. There are also beginner and advanced video lessons that I'm making with this system.

While I haven't sorted out the exact technology I'll use, I'm planning on making this a regular weekly live broadcast starting this fall. To be ready, I'd like to do one more test next Wednesday, August 7th at 3 PM EST (7 PM UTC).

I'd like to get four programming questions (1 hour show, 15 minutes each) signed up in advance. I'll then invite you to the hangout around 2:45 and we'll begin broadcasting at 3. If you'd like to participate, please write a question below with a link to any additional info (sketches, videos, git repos, etc.) I'm not sure exactly what I'm looking for, but I'm hoping to learn about what works best through

void setup() {
size(400,400);
}
void draw() {
float percent = map(mouseX,0,width,0,1);
background(0);
@shiffman
shiffman / spherical.pde
Created November 13, 2013 03:27
Spherical coordinates in Processing
void setup() {
size(600, 600, P3D);
}
void draw() {
background(0);
translate(width/2, height/2);
rotateX(frameCount*0.02);
rotateY(frameCount*0.03);
randomSeed(4);
@shiffman
shiffman / AverageDemo.pde
Created November 18, 2013 15:33
Demonstration of averaging an array of values in Processing
// Average of values over time
// Daniel Shiffman
int[] values = new int[20];
void setup() {
size(300, 300);
}
@shiffman
shiffman / LerpDemo.pde
Created November 18, 2013 15:35
Simple demonstration of lerp (as compared to average demo).
// Simple interpolated value demonstration
// Daniel Shiffman
float lerpedMouseX;
void setup() {
size(300, 300);
}
void draw() {
@shiffman
shiffman / soundonandoff.pde
Created November 22, 2013 17:00
How to fade a sound in and out using minim.
import ddf.minim.*;
AudioPlayer player;
Minim minim;
boolean fading = false;
void setup() {
size(400, 300, P2D);
minim = new Minim(this);