Skip to content

Instantly share code, notes, and snippets.

View timpulver's full-sized avatar

Tim Pulver timpulver

View GitHub Profile
@timpulver
timpulver / getDataDirectory.pde
Created July 12, 2012 16:56
[P5] How to get the DATA directory
//Sometimes we need the path to the Processing data directory.
// creates a virtual file within the data directory
File file = new File(dataPath("") + File.separator + "a_filename.txt");
//using dataPath("..."), the path can be altered, too (when using "", this is not the case).
@timpulver
timpulver / liveLineOutSignal.pde
Created July 12, 2012 18:06
[P5, Minim] Using live line out signal
/*
* make sure, you have activated stereomix as your recording device in your system settings!
*/
import ddf.minim.*;
import ddf.minim.signals.*;
Minim minim;
AudioInput in;
SineWave sine;
@timpulver
timpulver / imgurImageUpload.java
Created August 20, 2012 17:49
Upload an image to image hoster Imgur (can be used for PGraphics, too)
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
@timpulver
timpulver / p5_keystroke_simulator.java
Created September 24, 2012 13:05
[Processing] Simulates a key press
import java.awt.AWTException;
import java.awt.Robot;
KeystrokeSimulator keySim;
void setup(){
keySim = new KeystrokeSimulator();
}
void draw(){
@timpulver
timpulver / IpFromUrl.java
Created September 24, 2012 15:15
[Java] URL to IP address lookup [host, url, ip, server, convert, conversion]
import java.net.*;
import java.io.*;
public static class IpFromUrl {
// Returns the IP address of an URL
// i.e. http://www.facebook.com -> 123.456.789.10
public static String getIp( String hostname ) throws IOException {
try {
InetAddress ipaddress = InetAddress.getByName(hostname);
System.out.println("IP address: " + ipaddress.getHostAddress());
@timpulver
timpulver / transparentWindow.java
Last active October 11, 2015 00:48
[Processing 2.0] Create Transparent Window [Java, Frame]
/**
* Author: Tim Pulver
* Date: 2013
* Tested with Processing 2.0
* original code by jungalero (processing.org forum)
*/
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.Rectangle;
@timpulver
timpulver / CallerWithParams.pde
Created September 24, 2012 16:41
[Processing] Reflection Test [Java, Reflection API]
import java.lang.reflect.*;
import java.io.File;
class CallerWithParams{
/**
@param o the object which contains the method to call,
when passing 'this' from within the processing main sketch,
all functions in your main sketch will be recognized
(setup(), draw(),..., custom methods)
@param m the name of the method to call without "()"
@timpulver
timpulver / threshold.pde
Created September 25, 2012 12:58
[Processing] Image Threshold [Image manipulation, effect]
class Threshold{
/**
* Returns a new PImage with threshold thresh in Grayscale.
* All coulours will be splitted according to their
* brightness between black and white.
*/
PImage threshold(PImage pi, int thresh){
if(pi==null || thresh < 0 || thresh > 255){ // invalid argument
println("threshold(): PImage == 0 or threshold value not in range [0..255]");
@timpulver
timpulver / deleteFoldersWithOneFile.pde
Created September 26, 2012 12:29
[Processing] Delete all folders with only one file
String parentFolder = "M:\\INSERT_PARENT_DIR_HERE";
void setup(){
File tmpDir;
File fParentFolder = new File(parentFolder);
println("Scanning " + fParentFolder.getAbsolutePath());
println("Folder exists: " + fParentFolder.exists());
File[] folderList = fParentFolder.listFiles();
println("Number of files/folders: " + folderList.length);
println("-----------------------------------");
@timpulver
timpulver / dinPageFormats.pde
Created October 14, 2012 09:18
[Processing] Specifying PDF page size in Processing (Processing 2.0 alpha)
import processing.pdf.*;
import com.lowagie.text.PageSize;
import com.lowagie.text.Rectangle;
/**
* Hack to use dinA paper formats
* Originally posted by http://toxi.co.uk, I made small changes to use it with Processing 2.0 alpha.
*/