Loading...
Processing Forum
Recent Topics
All Forums
Screen name:
josephinejost.com
About Me:
Designer, Artist, Mum. Co-Founder / Designer at 8 Pixeldrops
Website:
http://www.josephinejost.com
Twitter Link:
https://twitter.com/josephinejost
Facebook Link:
https://www.facebook.com/pages/Josephine-Jost/121924444540179
josephinejost.com's Profile
2
Posts
10
Responses
0
Followers
Activity Trend
Last 30 days
Last 30 days
Date Interval
From Date :
To Date :
Go
Loading Chart...
Posts
Responses
PM
Show:
All
Discussions
Questions
Expanded view
List view
Private Message
Changing source image in between a sequence
[13 Replies]
10-Jul-2012 05:46 AM
Forum:
Programming Questions
I've got this Pointillism code, just wondering if there's a way to switch the image that is processed/referenced half way through the sequence:
// Learning Processing
// Daniel Shiffman
//
http://www.learningprocessing.com
// Example 15-14: "Pointillism"
PImage img;
int pointillize = 15;
void setup() {
size(800,500);
img = loadImage("20.JPG");
background(255);
smooth();
}
void draw() {
// Pick a random point
int x = int(random(img.width));
int y = int(random(img.height));
int loc = x + y*img.width;
// Look up the RGB color in the source image
loadPixels();
float r = red(img.pixels[loc]);
float g = green(img.pixels[loc]);
float b = blue(img.pixels[loc]);
// Back to shapes! Instead of setting a pixel, we use the color from a pixel to draw a circle.
noStroke();
fill(r,g,b,90);
rect(x,y,pointillize,pointillize);
saveFrame("/output/seq-####.jpg");
}
Facebook Graph API
[8 Replies]
20-Jun-2012 09:07 AM
Forum:
Programming Questions
Hi, I want to integrate my own facebook profile into Processing using the Graph API, to create something like this:
http://www.youtube.com/watch?v=ZL62fF6Uzjo
Here is the code I'm using:
// application api key and secret
String fbApiKey = "mykey";
String fbApiSecret = "mysecretapi";
// a comma separated (no spaces!) list of user ids
String fbUserIDs = "myid";
/* other settings */
//
// Facebook RESTful API
String fbRestServer = "";
String fbRestNode = "";
XMLElement[] usersXml;
int currentUser = 0;
void setup ()
{
size( 300, 200 );
// the details / params in here define what will be read, see:
//
http://wiki.developers.facebook.com/index.php/Users.getInfo
String xmlResponse = fbCallMethod( new String[] {
"method=facebook.Users.getInfo",
"uids=" + fbUserIDs,
"fields=uid,first_name,last_name", // see link above for more options
"format=XML"
});
if ( xmlResponse == null ) // an error occured
{
exit();
return;
}
XMLElement xml = new XMLElement( xmlResponse );
usersXml = xml.getChildren( "user" );
fill( 0 );
textFont( createFont( "sans-serif", 24 ) );
textAlign( CENTER );
frameRate( 1 );
}
void draw ()
{
background( 255 );
String full_name = usersXml[currentUser].getChild("first_name").getContent();
full_name += " " + usersXml[currentUser].getChild("last_name").getContent();
text( full_name, width/2, height/2 );
currentUser++;
currentUser %= usersXml.length; // modulo, wrap around
}
/**
* Place a Facebook call (GET request) using Processing API ( loadStrings(), join() )
*/
String fbCallMethod ( String[] args )
{
String[] params = new String[args.length + 3];
System.arraycopy( args, 0, params, 0, args.length );
params[params.length-3] = "api_key=" + fbApiKey;
params[params.length-2] = "call_id=" + System.currentTimeMillis();
params[params.length-1] = "v=1.0";
String sig = fbGenerateSIG ( params );
String paramString = join( params, "&" ) + "&sig=" + sig;
String[] lines = loadStrings( fbRestServer + fbRestNode + "?" + paramString );
if ( lines == null )
{
println( "OUCH, nothing to read from that URL:\n" + fbRestServer + fbRestNode + "?" + paramString );
return null;
}
String response = join( lines, "\n" );
return response;
}
/**
* Generate a call signature, see:
*
http://wiki.developers.facebook.com/index.php/How_Facebook_Authenticates_Your_Application
*
http://wiki.developers.facebook.com/index.php/Authorization_and_Authentication_for_Desktop_Applications
*/
String fbGenerateSIG ( String[] args )
{
java.util.Arrays.sort( args );
String argString = join( args, "" );
argString += fbApiSecret;
return md5Encode( argString );
}
/**
* MD5 encode a String using Processing API ( hex() )
*/
String md5Encode ( String data )
{
java.security.MessageDigest digest = null;
try {
digest = java.security.MessageDigest.getInstance("MD5");
}
catch ( java.security.NoSuchAlgorithmException nsae ) {
nsae.printStackTrace();
}
digest.update( data.getBytes() );
byte[] hash = digest.digest();
StringBuilder hexed = new StringBuilder();
for ( int i = 0; i < hash.length; i++ )
{
hexed.append( hex( hash[i], 2 ) );
}
return hexed.toString().toLowerCase();
}
And the Error messages I get:
java.lang.IllegalArgumentException: Prefix string too short
at java.io.File.createTempFile(File.java:1782)
at java.io.File.createTempFile(File.java:1828)
at processing.app.Base.createTempFolder(Base.java:1566)
at processing.app.Sketch.makeTempFolder(Sketch.java:1112)
at processing.mode.java.JavaBuild.build(JavaBuild.java:135)
at processing.mode.java.JavaMode.handleRun(JavaMode.java:176)
at processing.mode.java.JavaEditor$20.run(JavaEditor.java:481)
at java.lang.Thread.run(Thread.java:662)
«Prev
Next »
Moderate user : josephinejost.com
Forum