We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
like a flash (Read 1002 times)
like a flash
Jan 24th, 2010, 5:07am
 
how can I do to reveal a picture and remove it immediately like a flash? there is anyone who can help me?
Thanks Smiley
Re: like a flash
Reply #1 - Jan 24th, 2010, 5:29am
 
Quote:
/// Directions: Click mouse, get flashed.

boolean flashHim = false;

void draw(){
  if( flashHim ){
    drawFlashyThing();
  } 
  else {
    drawBoringThing();
  }
  flashHim = false;
}

void drawFlashyThing(){
  background(255,0,0);
  for(int i=0;i<20;i++){
    fill(random(128,255),random(128,255),random(128,255));
    rect(random(width),random(height),random(width),random(height));
  }
}

void drawBoringThing(){
  background(0);
}

void mouseClicked(){
  flashHim = true;
}

Re: like a flash
Reply #2 - Jan 24th, 2010, 5:51am
 
This is fine but I wanted to know in particular how an image appears and disappears without using the mouse but automatically .... Embarrassed
Re: like a flash
Reply #3 - Jan 24th, 2010, 6:04am
 
It depends on what criterions you want to make it appear.
Can be as simple as:
Code:
void draw() {
if (random(100) <= 1) {
drawFlashyThing();
} else {
drawBoringThing();
}
}

with the image appearing randomly roughly once every 100 frames.
Re: like a flash
Reply #4 - Jan 24th, 2010, 6:16am
 
this is my code...it is an animation...

int speedx = 20;
int speedy = 20;
int speeda = 8;
int speedb = 8;
int speedc = 10;
int x=640;
int y=640;
int ya=-130;
int a = 220;
int b = 5;
int c = 5;
int e = 300;
int f = 100;
boolean s= true;

void setup (){
 size (640,479);
}
 PImage []images = new PImage[9];
 
void draw (){
images [0] = loadImage ("sole.png");
image (images[0],91,522);
images[1]= loadImage("sfondo.png");
 background(images[1]);
 x-=speedx;
 images [2]=loadImage ("dirigibile.png");
 image (images[2],x,50);
 
    if (x<=-300){
      fill (#001600);
      a = a + speeda;
      ellipse (510, a, 3, 3);
    }
   
  if (a >=380){
    a=380;
    y-=speedy;
    images[3]=loadImage ("nuvolaS190.png");
    image (images[3],y,50);
   ya+=speedy;
  images[5]= loadImage ("nuvolaS170.png");
  image (images[5],ya,40);
  images[6]=loadImage ("nuvolaS180.png");
  image (images[6],250,ya-90);
  }
 
 if (y <=400){
   images[4]= loadImage("sfondopioggia.png");
 background(images[4]);
 
 speedy=0;
 image(images[3],y,50);
 image(images[5],ya,40);
 image(images[6],250,ya-90);
 images[7]=loadImage ("saetta100.png");
 image (images[7],299,118);
 
 e+=speeda;
 f+=speedb;
 images[8]=loadImage ("goccia10.png");
 image (images[8],e,f);
 
 

 }

 
   
}



The images[7]  appears but after about two seconds should disappear and the rest remain the same ....
I apologize that the code is a bit messy Embarrassed
Re: like a flash
Reply #5 - Jan 24th, 2010, 7:57am
 
BEGONE, MESSY CODE!

Quote:
int speedx = 20;
int speedy = 20;
int speeda = 8;
int speedb = 8;
int speedc = 10;
int x = 640;
int y = 640;
int ya = -130;
int a = 220;
int b = 5;
int c = 5;
int e = 300;
int f = 100;
boolean s = true;
PImage images[];

void setup (){
 size( 640, 479 );
 images = new PImage[9];
 images[0] = loadImage("sole.png");
 images[1] = loadImage("sfondo.png");
 images[2] = loadImage("dirigibile.png");
 images[3] = loadImage("nuvolaS190.png");
 images[4] = loadImage("sfondopioggia.png");
 images[5] = loadImage("nuvolaS170.png");
 images[6] = loadImage("nuvolaS180.png");
 images[7] = loadImage("saetta100.png");
 images[8] = loadImage("goccia10.png");
}

void draw (){
 
 image( images[0], 91, 522 );
 background( images[1] );
 x -= speedx;
 image( images[2], x, 50 );
 
 if( x <= -300 ){
   fill( 0, 22, 0 ); // #001600
   a = a + speeda;
   ellipse(510, a, 3, 3);
 }

 if( a >= 380 ){
   a = 380;
   y -= speedy;
   image( images[3], y, 50 );
   ya += speedy;
   image( images[5], ya, 40 );
   image( images[6], 250, ya-90 );
 }

 if( y <= 400 ){
   background( images[4] );
   speedy = 0;
   image( images[3], y, 50 );
   image( images[5], ya, 40 );
   image( images[6], 250, ya-90 );
   image( images[7], 299, 118 );
   e += speeda;
   f += speedb;
   image( images[8], e, f );
 }
 
}



Also, you only need to load the images once, in setup().

Right, now, what's still wrong with it?
Re: like a flash
Reply #6 - Jan 24th, 2010, 8:35am
 
in the sketch images [7]  should disappearafter it appeared . In practice the image is a lightning in the animation appears and disappears. I do not know how to give this effect ....
Re: like a flash
Reply #7 - Jan 24th, 2010, 10:02am
 
The whole is redrawn each time draw() is called.
So to make an image to flash, you must find out the conditions when it must appear on a given frame, and ensure the conditions are not meet again on the next frame (or n frames later). Can be every n frames, after n seconds, etc.
Re: like a flash
Reply #8 - Jan 25th, 2010, 4:04am
 
I tried but if I do I will block other things
Re: like a flash
Reply #9 - Jan 25th, 2010, 4:55am
 
Well, show what you tried, so we can see what conditions you mean to use.
Page Index Toggle Pages: 1