saulbass
YaBB Newbies
Offline
Posts: 3
Re: Basic animation problem
Reply #2 - Dec 14th , 2005, 5:49pm
irag, thanks for taking the time to answer my query. I've looked at your reply and I think perhaps I didn't phrase my question clearly enough. I was wondering if I could force a screen draw update inside a 'for' loop i.e. for(int a=b; a<80+b; a+=20) { line(0, a, 200, a); draw(); } Your example is similar to Reas's original in that the screen update happens at the end of the draw() loop iteration. Perhaps my confusion is just due to my unfamiliarity with the Processing code flow. Am I right in thinking that the draw() command is the actual command that issues a screen update? In this case when the code reaches a command like: line(0, a, 200, a); I assume it updates a hidden screen memory area and when it reaches the end of the draw() loop it then updates the screen with this hidden buffer. I should perhaps explain further what I am looking to do with Processing. Simply put, I want to make a simple slide show presentation program - taking a sequence of images (fname.1.jpg,fname.2.jpg,.....,fname.100.jpg) and dissolve from one to another. i.e. mix from fname1.jpg to fname2.jpg then mix to fname3.jpg etc; This is what I have come up with so far: // SlideShow by Saulbass 14 Dec 2005 PImage a,b; // seems to be needed for loadimage to work void setup() { size(200, 200); // Size should be the first statement. Image size String dummy = "../dummy.jpg"; // set String to a dummy image name a = loadImage(dummy); b = loadImage(dummy); // 'declare' both images PFont fontA = loadFont("../CourierNew36.vlw"); textFont(fontA, 12); // font setup } //Declare main loop variables here. (not in setup). float Maxlcv = 255; // Maximum value of loop count variable, lcv. //Can be adjusted along with DissolveSpeed to control rate of transition. float lcv = Maxlcv; //loop count variable float transp; // transparency variable String prefix = "../TestWallJPGs/TestWallJPGs."; String suffix = ".jpg"; // String variables pointing to files int BufferANum = 1; int BufferBNum = BufferANum - 1; // variables for buffers a and b String bufferA = prefix+BufferANum+suffix; // buffer a destination String String bufferB = prefix+BufferBNum+suffix; // buffer b destination String float DissolveSpeed = 40; // Controls the speed of the dissolve. i.e try .(max 60) or (min0.5) int SequLen = 132; // Maximum count of frames in sequence. void draw() // Main SlideShow loop { transp = lcv ; // set transp variable background(0); // Set the background to black in between each drawing. tint(255,255); // set the tint to full alpha image(a, 0, 0); // display image a tint(255,transp); // set the tint value - colour,alpha to slowly dissolve on buffer b image(b, 0, 0); // display image b //text(BufferANum,0,250); // give a visual indication of current BufferANum if needed. lcv = lcv - DissolveSpeed; //decrement loop variable. Change this to speed up the dissolve if (lcv < 0) // do this until lcv = 0, then reset lcv to 255, and update the image stores { lcv = Maxlcv; // reset the loop counter BufferANum = BufferANum + 1; // increment the buffer a frame number BufferBNum = BufferANum - 1; // update the buffer b frame number String bufferA = prefix+BufferANum+suffix; // update the strings String bufferB = prefix+BufferBNum+suffix; // update the strings a = loadImage(bufferA); // update image in the a buffer. b = loadImage(bufferB); // update image in the b buffer. if (BufferANum > SequLen) {BufferANum = 1;} // Reset the BufferANum loop if it goes beyond sequence length } } And it seems to work fairly well. (Notice I haven't used any 'for' structures!) I suppose I was hoping to structure it as follows: for framenum = 1 to sequencelength step 1 for transp = 1 to 255 step 10 display bufferA display bufferB (with varying transparency) next transp next framenum (in a very simplified form...) but I'm coming to the conclusion that this isn't Processings way... I'm assuming that I can export this SlideShow as a java app and that I can then setup my mac (running 10.3) to autorun & present this SlideShow java app from startup so that the machine will effectively act as a full frame automatic SlideShow presenter. (I haven't yet looked at this in detail, I just wanted to check that this is possible in theory). Finally one other question! I've tried my simple SlideShow sketch on an Dual G4/866 Mac (10.3) and a Pentium 4 2Ghz (XP) and with a large image size of say 1024x768 the screen update is very slow. Is there anything I can do speed up my SlideShow sketch? Many thanks, Saulbass.