gregpond
YaBB Newbies
Offline
Posts: 6
Re: PImage syntax/location
Reply #5 - Nov 15th , 2006, 12:19am
Kevin McCoy and I got it to work. We brought the binary generator into processing, removed the data from pd coming via OSC all together and wrote a new "void imageNumber" for each image we need to call. It is easy to run through a sequence. If any one knows why a PImage variable cant be re-designated as we had tried to do in our first try please let me know. thanks, working code follows (for some reason I cant to figure out how to post code as "code" with my browser so I have to paste it as it appears below): int posx = 0; int posy = 0; int numdivx = 256; int numdivy = 192; int imageLink = 0; int r; String binseq; int refPoint = 0; boolean parsed = true; char message; PImage a; PImage b; //int currentpic = 0; void setup() { //define PImages a = loadImage("a.jpg"); b = loadImage("b.jpg"); // PFont fontA = loadFont("Verdana-6.vlw"); textFont(fontA, 6); size(1024,768); frameRate(800); background(255); noStroke(); fill(0); } // The font must be located in the sketch's // "data" directory to load successfully //fonty = loadFont("Verdana-12.vlw"); void draw() { if (parsed==false) { message = binseq.charAt(refPoint); refPoint+=1; //println(refPoint); if(refPoint>7) {refPoint = 0; parsed = true;} imageChooser(); } if (parsed==true) { r = int(random(128, 256)); binseq = binary(r); //println(binseq); parsed = false; } } void imageChooser() { if(imageLink==0) {imageOne();} if(imageLink==1) {imageTwo();} } void imageOne(){ //fill(255,5); //rect(0,0,width,height); int msgval = message; if(msgval=='1'){ fill(255); rect(width/numdivx*posx,height/numdivy*posy,width/numdivx,height/numdivy); fill(a.get(posx,posy),30); rect(width/numdivx*posx,height/numdivy*posy,width/numdivx,height/numdivy); fill(a.get(posx,posy)); pushMatrix(); translate(0,height/numdivy); text("1",width/numdivx*posx,height/numdivy*posy); popMatrix(); } else{ fill(255); rect(width/numdivx*posx,height/numdivy*posy,width/numdivx,height/numdivy); fill(a.get(posx,posy),30); rect(width/numdivx*posx,height/numdivy*posy,width/numdivx,height/numdivy); fill(a.get(posx,posy)); pushMatrix(); translate(0, height/numdivy); text("0",width/numdivx*posx,height/numdivy*posy); popMatrix(); } posx+=1; if(posx==numdivx){ if(posy==numdivy-1) { imageLink = 1; } } if(posx>numdivx) {posx = 0; posy+=1;} if(posy>numdivy-1) {posy = 0;} } void imageTwo(){ //fill(255,5); //rect(0,0,width,height); int msgval = message; if(msgval=='1'){ fill(255); rect(width/numdivx*posx,height/numdivy*posy,width/numdivx,height/numdivy); fill(a.get(posx,posy),30); rect(width/numdivx*posx,height/numdivy*posy,width/numdivx,height/numdivy); fill(b.get(posx,posy)); pushMatrix(); translate(0,height/numdivy); text("1",width/numdivx*posx,height/numdivy*posy); popMatrix(); } else{ fill(255); rect(width/numdivx*posx,height/numdivy*posy,width/numdivx,height/numdivy); fill(a.get(posx,posy),30); rect(width/numdivx*posx,height/numdivy*posy,width/numdivx,height/numdivy); fill(b.get(posx,posy)); pushMatrix(); translate(0, height/numdivy); text("0",width/numdivx*posx,height/numdivy*posy); popMatrix(); } posx+=1; if(posx==numdivx){ if(posy==numdivy-1) { imageLink = 0; } } if(posx>numdivx) {posx = 0; posy+=1;} if(posy>numdivy-1) {posy = 0;} }