fullscreen class Cubo
{
PVector initPos = new PVector();
PVector scaleRatio = new PVector();
Photo p;
PImage tImg;
int id;
int rndr; // 0 cubes , 1 texts
float[] coords = {
/*+z front*/-1, -1, 1, 1, -1, 1, 1, 1, 1, -1, 1, 1,
/*-z back*/ 1, -1, -1, -1, -1, -1,-1, 1, -1, 1, 1, -1,
/*+y bottom*/ -1, 1, 1 ,1, 1, 1, 1, 1, -1 ,-1, 1, -1,
/*-y top*/ -1, -1, -1, 1, -1, -1, 1, -1, 1, -1, -1, 1,
/*+x right*/ 1, -1, 1, 1, -1, -1, 1, 1, -1, 1, 1, 1,
/*-x left*/-1, -1, -1, -1, -1, 1, -1, 1, 1, -1, 1, -1
};
Cubo(PVector _initPos, PVector _scaleRatio, int _id)
{
initPos = _initPos;
scaleRatio = _scaleRatio;
id = _id;
tImg = tempImage;
rndr = 0;
}
void render()
{
if(id <= photos.size()-1){
p = (Photo) photos.get(id);
switch (rndr) {
case 0:
p.doLoad();
if(p.loaded)
tImg = p.imgHolder;
noStroke();
noFill();
rotateY(radians(90));
for(int i = 0; i <= 60; i+=12){
beginShape(QUADS);
texture(tImg);
vertex(coords[i]*scaleRatio.x, coords[i+1]*scaleRatio.y, coords[i+2]*scaleRatio.z, 0, 0);
vertex(coords[i+3]*scaleRatio.x, coords[i+4]*scaleRatio.y, coords[i+5]*scaleRatio.z, 1, 0);
vertex(coords[i+6]*scaleRatio.x, coords[i+7]*scaleRatio.y, coords[i+8]*scaleRatio.z, 1, 1);
vertex(coords[i+9]*scaleRatio.x, coords[i+10]*scaleRatio.y, coords[i+11]*scaleRatio.z, 0, 1);
endShape();
}
break;
case 1:
textSize(.4);
fill(0);
String temp = p.desc;
float tempW = textWidth(temp);
pushMatrix();
//translate(0,-10,0);
rotateY(radians(-90));
rotateZ(radians(-90));
text(temp,0,0,0);
popMatrix();
break;
}
}
}
void setRndr(int _rndr){
rndr = _rndr;
}
}
void hud(PeasyCam cam)
{
cam.beginHUD();
pushMatrix();
translate(100, height-120, 0);
fill(255, 200);
noStroke();
rect(0,0,50,20);
textSize(8);
fill(0, 100);
text("Keyword", 8, 14);
float tw = textWidth(searchString);
fill(255, 200);
noStroke();
rect(50,0,tw+10,20);
fill(0, 255);
text(searchString, 50, 14);
stroke(0, 200);
if(second()%2 == 0)
line(tw+52, 14, tw+57, 14);
if(searchState.equals("nomatches")){
stroke(0);
noFill();
rect(1,30, 65, 30);
fill(0, 200);
text("No matches!", 8, 50);
}
if(searchState.equals("fail")){
stroke(0);
noFill();
rect(1,30, 170, 30);
fill(0, 200);
text("Parameterless search is not allowed!", 8, 50);
}
popMatrix();
cam.endHUD();
}
class Photo{
PImage img, imgHolder;
boolean loaded;
String desc;
public Photo(String url, String _desc) {
imgHolder = tempImage;
img = requestImage(url);
loaded = false;
desc = _desc;
}
void doLoad(){
if (img.width == 0) {
loaded = false;
} else if (img.width == -1) {
loaded = false;
} else {
loaded = true;
switchImg();
}
}
void switchImg(){
imgHolder = img;
}
}
/**
*
* @author US02515
*/
public class Pxy extends Authenticator {
private String user, password;
public Pxy(String user, String password) {
this.user = user;
this.password = password;
}
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(user, password.toCharArray());
}
}
class Sfera {
float radius;
float increment;
List<Cubo> cubi;
int i;
String srchString;
int state;
Sfera(float se, String _srchString) {
photos.clear();
radius = se;
srchString = _srchString.trim().replace(' ','+');
increment = 2.05/se;
cubi = new LinkedList<Cubo>();
i = 0;
state = 0;
creaSfera();
}
void creaSfera() {
for(float theta =- PI/2.5; theta < PI/2; theta = theta+increment){
float sinz=sin(theta);
float cosz=cos(theta);
for(float phi=0; phi<TWO_PI; phi = phi+(increment)){
float sin = sin(phi); //sine of x,y angle
float cos = cos(phi); //cosine of x,y angle
float sin1 = sinz; //redeclare
float cos1 = cosz;
float x = cos1*cos*radius; //scale x to z position
float y = cos1*sin*radius; //repeat
float z = sin1*radius; //z
cubi.add(new Cubo( new PVector(x,y,z), new PVector(1.0,random(0.01,1.0),1.0), i));
i++;
}
}
//http://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=99835d77b01b776f3115b56180c6c4f4&text="+srchString+"&per_page="+cubi.size();
//"http://api.flickr.com/services/rest/?method=flickr.people.getPublicPhotos&api_key=99835d77b01b776f3115b56180c6c4f4&user_id=24662369@N07&text="+srchString+"&per_page="+cubi.size());
loadImagesFromApiCall("http://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=99835d77b01b776f3115b56180c6c4f4&text="+srchString+"&per_page="+cubi.size());
}
void render() {
for (Cubo cbo:cubi){
cbo.setRndr(state);
PVector c = new PVector(cbo.initPos.x-0,cbo.initPos.y-0,cbo.initPos.z-0);
float h = dist(0,0,0,c.x,c.y,c.z);
float r = sqrt(pow(c.x,2)+pow(c.y,2)+pow(c.z,2));
float thetab = atan2(c.y,c.x);
float phib = acos(c.z/r);
pushMatrix();
translate(cbo.initPos.x,cbo.initPos.y,cbo.initPos.z);
rotateZ(thetab);
rotateY(phib);
rotateX(-HALF_PI);
cbo.render();
popMatrix();
}
}
void destroy() {
cubi.clear();
}
void setState(int _state){
state = _state;
}
}
class Txtarea {
float aw,ah,ax,ay;
Txtarea(float _aw, float _ah, float _ax, float _ay){
aw = _aw;
ah = _ah;
ax = _ax;
ay = _ay;
}
void render()
{
cam.beginHUD();
pushMatrix();
translate(ax, ay, 0);
if(overRect())
fill(255, 255);
else
fill(255, 150);
noStroke();
rect(0,0,aw,ah); // textfield container
textSize(8);
fill(0, 100);
text("Keyword", 8, 14); // textfield
float tw = textWidth(searchString);
if(overRect())
fill(255, 255);
else
fill(255, 150);
noStroke();
rect(aw,0,tw+10,ah);
fill(0, 255);
text(searchString, aw, 14);
stroke(0, 200);
if(second()%2 == 0)
line(tw+aw+2, 14, tw+57, 14);
if(searchState.equals("nomatches")){
stroke(0);
noFill();
rect(1,30, 65, 30);
fill(0, 200);
text("No matches!", 8, 50);
}
if(searchState.equals("fail")){
stroke(0);
noFill();
rect(1,30, 170, 30);
fill(0, 200);
text("Parameterless search is not allowed!", 8, 50);
}
popMatrix();
cam.endHUD();
}
boolean overRect()
{
float dw = 150.0;
if (mouseX >= ax && mouseX <= ax+aw+dw && mouseY >= ay && mouseY <= ay+ah) {
return true;
} else {
return false;
}
}
}
/**
* Flickr PhotoSphere 0.9.0
* DEC 30 2010 Gian Carlo Mingati
*
*/
import processing.video.*;
//MovieMaker mm;
import peasy.org.apache.commons.math.*;
import peasy.*;
import peasy.org.apache.commons.math.geometry.*;
import proxml.*;
import proxml.XMLElement;
XMLElement xml;
XMLInOut xmlIO;
PImage tempImage;
PeasyCam cam;
Txtarea t;
PFont imhelix;
Sfera s;
String searchString;
String searchState = "";
List<Photo> photos = new LinkedList<Photo>();
void setup(){
size(640,480,P3D);
tempImage = loadImage("flickr.jpg");
searchString = "fender stratocaster";
s = new Sfera(random(5.0, 10.7), searchString); //5.0 min 10.7 max
imageMode(CENTER);
textureMode(NORMALIZED);
imhelix = loadFont("imhelix2_8pt_0904_11-32.vlw");
textFont(imhelix);
cam = new PeasyCam(this,50);
cam.rotateX(-HALF_PI);
t = new Txtarea(50,20,100,height-120);
//mm = new MovieMaker(this, width, height, "drawing.mov", 30, MovieMaker.VIDEO, MovieMaker.LOSSLESS);
}
void draw(){
background(245);
scale(2);
s.render();
t.render();
//mm.addFrame();
}
void keyPressed() {
if(key == ENTER){
s = new Sfera(random(5.0, 10.7), searchString);
}
else if(key == BACKSPACE){
if(searchString.length()>0)
searchString = searchString.substring(0,searchString.length()-1);
}
else if(keyCode == UP){
s.setState(0);
}
else if(keyCode == DOWN){
s.setState(1);
}
else if(keyCode == RIGHT){
//mm.finish();
}
else {
searchString += key;
}
}
void mouseClicked(){
if(t.overRect())
searchString = "";
}
void loadImagesFromApiCall(String callURL){
XMLInOut xmlIn = new XMLInOut(this);
try {
xmlIn.loadElement(callURL);
} catch(Exception e){}
}
void xmlEvent(XMLElement element){
XMLElement[] photoList;
if(element.getAttribute("stat").equals("ok")) {
searchState = "ok";
if(element.firstChild().getIntAttribute("total") != 0 ){
photoList = element.firstChild().getChildren();
for(int i = 0; i < photoList.length; i++)
{
String desc = photoList[i].getAttribute("title");
String farm = photoList[i].getAttribute("farm");
String server = photoList[i].getAttribute("server");
String id = photoList[i].getAttribute("id");
String secret = photoList[i].getAttribute("secret");
photos.add(new Photo("http://farm"+farm+".static.flickr.com/"+server+"/"+id+"_"+secret+"_s.jpg", desc));
}
}
else
searchState = "nomatches";
}
if(element.getAttribute("stat").equals("fail")){
searchState = "fail";
}
}
Cubes are texturized using a Flickr API call.
Type any key and press ENTER.
Key UP shows the images, Key DOWN shows the descriptions.
PeasyCam controls.