FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Syntax
(Moderators: fry, REAS)
   multiply and switch
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: multiply and switch  (Read 3416 times)
benelek

35160983516098 WWW Email
multiply and switch
« on: Feb 20th, 2003, 9:58am »

is it possible to run both a noBackground applet and a normal background applet on top of each other?
 
is it possible to switch between background/noBackground mid-applet?
 
one or both of these (probably both) could be a way to solve the need to draw everything to the screen on every iteration of the loop... as my programs grow, i've usually got a few different "pallets" open, and only one or a couple of them really need to be refreshed at a time.
 
even if these concurrent applet layers could only be solid rectangular, it would be a help.
 
thanks,
 
-jacob
 
REAS


WWW
Re: multiply and switch
« Reply #1 on: Feb 20th, 2003, 7:54pm »

you can easily switch between background and noBackground() and back but Processing won't store the buffer information. you need to create a new array of size width*height and explicitly save pixels[] and reload pixels[] each time you switch between the two modes if you want to save the data that is being written into the buffer when noBackground() is set.
 
here is a relevant but not exact example:
http://www.processing.org/learning/examples/vector_raster.html
 
i can explain in more detail if you prefer...
« Last Edit: Jan 17th, 2004, 8:59pm by REAS »  
benelek

35160983516098 WWW Email
Re: multiply and switch
« Reply #2 on: Feb 21st, 2003, 12:48am »

mm, this is cool. extremely helpful in programs where im just refreshing a view of something when the mouse is being dragged, etc. i tried the following, which worked well.
 
Code:

//testing a method of only refreshing when needed.
 
void setup() {
  size(500,300);
  background(100);
  noBackground();
  stroke(0);
  objaX=int(random(width));
  objbX=int(random(width));
  refresh();
}
 
boolean loopOn=false;
int objaX,objbX;
 
void loop() {
  if(loopOn==true) {
    refresh();
  }
}
 
void mousePressed() {
  background(100);
  loopOn=true;
}
 
void mouseReleased() {
  loopOn=false;
  noBackground();
}
 
void refresh() {
  //do ur normal loop stuff here.
   
  int addon=mouseX-pmouseX;
    objaX+=addon;
    objbX+=addon;
  if(objaX>width) {
    objaX=0;
    } else if(objaX<0) {
    objaX=width;
    }
  if(objbX>width) {
    objbX=0;
    } else if(objbX<0) {
    objbX=width;
    }
  rect(objaX, height/2+10, 20, 10);
  rect(objbX, height/2-10, 20, 10);
}

 
one question though...
 
sometimes when i release the mouse, only part of the background has been redrawn, leaving the rest of the background plain white. are the mousePressed/mouseReleased methods called at the exact moment the mouse button is activated, or do they operate in a fixed sequence before/after loop?
 
-jacob
 
fry


WWW
Re: multiply and switch
« Reply #3 on: Feb 21st, 2003, 1:57am »

mouse events are called as soon as they happen, which may be mid-loop.
 
also, the background is set just before your loop() function begins, so whatever background() or noBackground() setting you had when loop() last finished is what shows up as you start drawing.
 
 
Pages: 1 

« Previous topic | Next topic »