Skip to content

Instantly share code, notes, and snippets.

@shiffman
shiffman / no_ds_store.pde
Created November 17, 2014 21:24
List without DS_Store
String[] listFileNames(String dir) {
File file = new File(dir);
if (file.isDirectory()) {
String names[] = file.list();
StringList filelist = new StringList();
for (String s : names) {
if (!s.contains("DS_Store")) {
filelist.append(s);
void setup() {
size (400, 300); // make a canvas that's 300 x 300
//SETTING UP MY UNDERLYING GRID STRUCTURE
int numImages = 12;
int colWidth = 10; //column width
int rowHeight = 10; //row height
int colNum = width/colWidth;
int rowNum = height/rowHeight;
@shiffman
shiffman / saturation.pde
Created November 19, 2014 03:23
Algorithm for altering the saturation of a single color. (not using HSB mode).
color col;
void setup() {
size(200, 100);
col = color(50, 100, 25);
}
void draw() {
background(0);
noStroke();
@shiffman
shiffman / imageBase64.pde
Last active August 29, 2015 14:10
PImage encoded to Base64 String
// This is for Java 7
// With Java 8 you can now say:
import javax.xml.bind.DatatypeConverter;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;
// Load an image
PImage img = loadImage("file.jpg");
@shiffman
shiffman / node_getimage.js
Created December 10, 2014 03:11
Download an image from flickr with Node
var fs = require('fs');
var request = require('request');
var url = 'https://farm8.staticflickr.com/7484/15685407577_d19030d469_m.jpg';
var saveFile = 'test.jpg';
request.head(url, getImage);
function getImage(err, res, body) {
var req = request(url);
@shiffman
shiffman / samplep5dom.js
Created January 8, 2015 10:17
DOM Sample p5
var canvas;
var button;
function setup() {
// Make a canvas
canvas = createCanvas(100,100);
// Make an HTML DOM element, a button!
// The button will have the word "submit" in it
button = createButton("submit");
@shiffman
shiffman / CommonProcessingErrors.html
Last active August 29, 2015 14:23
Common Processing Errors
compile-time:
Missing a semi-colon ";"
Missing left parentheses "("
Missing right curly bracket "}"
The variable “myVar” doesn't exist.
The local variable “myVar” may not have been initialized.
The class “Thing” doesn't exist.
The function "myFunction()" expects parameters like this: myFunction(type, type, type, ...)
The method "function(type, type, type, ...)" doesn't exist.
Error on "_____"
@shiffman
shiffman / example1.ino
Last active August 29, 2015 14:23
Does this Processing code match properly with this Ardunio code?
int val;
void setup() {
Serial.begin(9600);
pinMode(3, INPUT);
}
void loop() {
val = analogRead(0);
Serial.write(val);
@shiffman
shiffman / checkbox.js
Last active August 29, 2015 14:24
Ideas for checkbox and select elements in p5.js
var checkbox;
function setup() {
checkbox = createCheckbox('the label');
checkbox.checked(true); // passing in an arg sets its state?
// What should this be called??
// it's wrapping 'onchange'
checkbox.changed(myCheckedEvent); // even for when the user does something
}
@shiffman
shiffman / movesketch.html
Last active August 29, 2015 14:27
Move a sketch into a div after it runs
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script language="javascript" src="../../lib/p5.js"></script>
<script language="javascript" src="sketch.js"></script>
<script language="javascript">
//$(document).ready(function() {
window.onload = function() {
$('#defaultCanvas').appendTo("#container");