//mobile processing code // thanks a lot to Francis Li from http://www.francisli.com/ // for mobile processing, Bluescan, the sample codes // upon this project is built as well // // the rest was written by Johannes Landstorfer http://hannes.emotisys.de // // internal notice, when running on my local computer // remove lock files (as root!) before starting emulator again! // comcon-server.port.lock, WMAServer.ports.lock // del d:\Java\wirelessToolkit\wtklib\*.lock // basic setup & variables ////////////////////////////////////////////////////// import processing.image2.*; import processing.bluetooth.*; Bluetooth bt; PFont standardfont; color bgcolor; color textcolor; // specific variables //////////////////////////////////////////////////////// // as arrays cant be expanded easily // set the max length to the number of people taking part // this might be obsolete once ArrayLists are in use int participants = 20; // define all "known" contacts here // note: as arrays cant be expanded easily in mobile p5 choose an arbitrary length here // and count the "filled slots" in an external variable Contact[] contactlist = new Contact[participants]; int contactlist_len = 0; // the collection process takes place in the background // contacts_found_pre collects all devices/contacts as soon as they are detected // at the end of each detection process it passes its contents to contacts_found and is reset // so that only devices that are currently detectable are transfered in the next run Contact[] contacts_found_pre = new Contact[participants]; int contacts_found_pre_len = 0; // once detection is complete, "publish" the contacts here Contact[] contacts_found = new Contact[participants]; int contacts_found_len = 0; // store all "personal" symbols in an array // the index in this array will correspond to the index of contactlist PImage[] symbols = new PImage[participants]; int symbols_len = 0; // when flipping through the images for display, this is the current index and the current image int contact_onstage; PImage symbol_onstage; // fading variables // the color of the layer that will fade in and out color curtain_color; // indicates whether the symbol has been exchanged (once per iteration) boolean change_symbol = true; // indicates whether fading-process is running or not boolean fader_flag = false; // steps from 0 to PI for sin-fading int fader_currstep = 0; // step-width, intended as float (range 0 - 3.14) but floats cant be assigned to vars (in mobile p5) int fader_rate = 60 *PI/314; // in mobile p5 PI=804... // setup of timer that will exchange the symbols on the screen int showtime = 1500; int timer_old = 0; int timer_now = 0; // variables more or less for debugging only int devices_count = 0; // count number of all devices available via bt int detectionruns_count = 1; // count number of detection runs String probe = "."; // a testing variable to check values on runtime // processing ///////////////////////////////////////////////////////// void setup() { //setup the stage and apperance framerate (20); bgcolor = color(50, 50, 50); textcolor = color(200, 180, 0); standardfont = loadFont("ArialMT-10.mvlw", textcolor, bgcolor); //"ArialMT-10.mvlw"; textFont (standardfont); background (bgcolor); // build a kind of fake address book // Contact (MAC-Adress of bluetooth device, name, symbol, position in the origininal list); // // (note on how p5code works): // it seems as the contactlist_len gets updated only after the [index] has been applied // but it is updated already in the "new Contact"construction contactlist[contactlist_len++] = new Contact ("000000000000", "he", "somepicture.png", contactlist_len-1); contactlist[contactlist_len++] = new Contact ("111111111111", "whoever", "somethingelse.png", contactlist_len-1); contactlist[contactlist_len++] = new Contact ("CCCCCCCCCCCC", "someone", "mysymbol.png", contactlist_len-1); /* */ // preload all images as loading on runtime slows processing down // complicates selection of images later a bit (> field "origindex" in Contact class) for (int c=0; c= timer_old + showtime) { fader_flag = true; timer_old = timer_now; } // fading-speed will be timed by the built-in framerate() and fader_rate if (fader_flag == true) { // use positive-half of sinus ( ((int)(PI/2)) && change_symbol == true) { if (contact_onstage < contacts_found_len - 1) contact_onstage++; // select next symbol else contact_onstage = 0; // or start with the first one again change_symbol = false; } } // we dont know if we will find friends (esp. not before the first detection is complete) if (contacts_found[contact_onstage] != null) symbol_onstage = symbols[contacts_found[contact_onstage].origindex]; // if something went wrong in the image construction, we cant show anyth. if (symbol_onstage != null) { /* resize would be nice but needs more tweaking because "createImage" is not available in mobilep5 //img.copy(srcImg, startx, starty, startwidth, startheight, // destx, desty, destwidth, destheight); PImage symbol_onstage = createImage(150, 200, RGB); copy(symbol_small, 0, 0, symbol_small.width, symbol_small.height, 0, 0, symbol_onstage.width, symbol_onstage.height); */ // show the image centered on the screen image(symbol_onstage, width/2 - symbol_onstage.width/2, height/2 - symbol_onstage.height/2); } // construct a new layer to fade in and out above the original image PImage2 curtain = new PImage2 (width, height); color curtain_color = color (bgcolor, (int)(sin(fader_currstep))); // sin(PI) = 255 in mobile p5 curtain.loadPixels(); for (int p=0; p