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)
   newbe problem again
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: newbe problem again  (Read 331 times)
Z3r0Fr0z3


newbe problem again
« on: Oct 27th, 2004, 12:20am »

Hi.
I'm in trouble whit this code http://digilander.libero.it/ZeroFroze/index.html
My intent was to trying several things with this code, but i dont understand why the litle one rectangle is redraw every time.
I have tried to use the draw() metod, but in this way i can't move the square.
 
Again i'm sorry for my bad english.
Thaks.
 
fjen

WWW
Re: newbe problem again
« Reply #1 on: Oct 27th, 2004, 12:34am »

i'm not sure what you are trying to do ...
 
the square attached to the mouse is drawn every time because it's in the loop. you might want to clear the screen inbetween? do the following:
 
move "BImage sfondo;" out of setup(){ .. } so you can access it from inside the loop.
 
inside the loop the first line should be:
image (sfondo,0,0);
 
now everytime processing enters the loop() it draws the image and therefore erases everything else.
 
did this solve your problem?
 
/F
« Last Edit: Oct 27th, 2004, 12:35am by fjen »  
Z3r0Fr0z3


Hi fjen, thanks for the repRe: newbe problem again
« Reply #2 on: Oct 27th, 2004, 1:03am »

Hi fjen, thanks for the reply.
Now it works, the square attached to the mouse was erased and in the same time i can remove the while function fron the alpha square.
 
I have another question now:
the older square were erased or reside under the image;
if they were not cancelled there is a way to clear the obsolete data?
 
fjen

WWW
Re: newbe problem again
« Reply #3 on: Oct 27th, 2004, 2:41pm »

happy to help.
 
i'm not sure what you are asking? if there is a call to reverse a drawing operation? no nothing like that in there.
the only thing you could do to get that effect is store the screen prior to drawing, then draw something, then put the old one back in place. that's something like your own custom undo ...
 
/F
 
Z3r0Fr0z3


Re: newbe problem again
« Reply #4 on: Oct 27th, 2004, 3:40pm »

Yes my intent was to remove the old drawn data.
In which way i can store the prior data of the blank screen?
Thank you for the help and excuse me for my bad english.
 
fjen

WWW
Re: newbe problem again
« Reply #5 on: Oct 27th, 2004, 4:40pm »

the idea is to jump back to a previous state, so this is not an reverse drawing function ... more like a step back.
 
example: click and drag the rect ... press z to jump back to previous screen. recording happens when you click inside the screen.
 
Code:

BGraphics prevScreen;
void setup () {
  size(200,200);
   
  // set up the BGraphics to record screen into
  prevScreen = new BGraphics(width, height);
  prevScreen.format = RGBA;
 
}
boolean handleonce = true;
void loop () {
  if (mousePressed)  {
    if (handleonce) {
 // when the mouse is pressed record the screen _once_.
 // i actually just copy the pixels array here
 System.arraycopy(pixels,0, prevScreen.pixels,0, pixels.length);
 // i could have done this as well to copy the pixels, the above is faster though:
 /*
   for (int i=0; i<pixels.length; i++) prevScreen.pixels[i] = pixels[i];
 */
 handleonce = false; // make sure it's only copied once.
    }
    background(128);
    rect(mouseX,mouseY, 20,20);
  } else  {
    fill (50 + random(150)); noStroke();
    handleonce = true;
    if (key == 'z' || key == 'Z') {
 // if the z or shift-z keys are pressed, reset screen to recorded state
 image(prevScreen, 0,0, width,height);
 key = -1;
    }
  }
}

 
/F
 
Z3r0Fr0z3


Re: newbe problem again
« Reply #6 on: Oct 27th, 2004, 8:13pm »

Ok, now i study it, thank you for the help.
 
Pages: 1 

« Previous topic | Next topic »