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.
IndexProgramming Questions & HelpPrograms › animating gifs at different times, sizes, location
Page Index Toggle Pages: 1
animating gifs at different times, sizes, location (Read 973 times)
animating gifs at different times, sizes, location
Jun 27th, 2007, 1:43am
 
Hello, I'm a rookie trying to figure out how to display a series of gifs that create a flower within draw(), the problem I'm having is that they happen on the end of vines and shouldn't start appearing until the vine stops growing, I'll get the first frame to appear and that's it---I'm putting down all the code that seems relevant (none of the code that has to do with the vine, background, etc) in hopes to cut down on the glut, but hopefully I didn't leave out anything too crucial.

ArrayList a,b,c,d;
Vine v,v02,v03,v04;

void setup(){
 a = new ArrayList();

Vine v = new Vine(new CompStore(random((width/4)-85,(width/4)+5),height-100.0), new CompStore(-PI-1.5707), 100.0, 0.01, random(-PI+1.5707,-0.5), -1);

a.add(v);
}


void draw(){

 Vine v = (Vine) a.get(0);
 v.fdisplay();
 v.update();
 v.render();

if(v.timeToSplit()){
  v.fdisplay()
  a.remove(0);
  //new vine
  a.add(v.splitOff());
 }

class Vine{

//variables for flower animation
 float animLocX;
 float animLocY;
 float animBaseX;
 float animBaseY;
 float animRad;
 boolean animSwitch;
 PImage[] flower = new PImage[5];
 int frame = -1;

boolean timeToSplit(){
   if(startAngle.count<=timer){
    return false;
   }else{
//this only seems to work once, the values only change for the one frame
//is this  a scope issue?
   animRad = rad;
   animBaseX = base.x;
   animBaseY = base.y;
   animLocX=loc.x;
   animLocY=loc.y;  
   animSwitch = true;
   return true;
   }
 }

void loadImages(String name) {
   for(int i=0; i<5; i++) {
     String imageName = name + "0" + i + ".gif";
     flower[i] = loadImage(imageName);
   }
 }

 void fdisplay(){
   float bigness=animRad*0.5+15;
   frame++;
   if(frame<4&&animSwitch==true){
   pushMatrix();
   translate(animLocX-bigness/2, animLocY-bigness/2);
   image(flower[frame], animBaseX, animBaseY, bigness, bigness);
   popMatrix();
   }else{frame=-1;animSwitch=false;}
 }

}

thanks, for the time
Re: animating gifs at different times, sizes, loca
Reply #1 - Jun 27th, 2007, 1:27pm
 
set up a flag so you know when the vine branches stop growing or being created and then display the images at the end of those branches..
or count the branches so u know when it reaches that count, it stoped growing and then display the image
Re: animating gifs at different times, sizes, loca
Reply #2 - Jun 27th, 2007, 4:34pm
 
The animSwitch is supposed to be what I think is a flag. The problem is that even though it's declared in the class vine, when I change it's value in timeToSplit() the new value doesn't stick outside of the if block up in draw().

I'm going to try giving the flowers their own individual count, though it seems as if it should be redundant as it will have to be the same as the vine's.

thanks for the reply
Re: animating gifs at different times, sizes, loca
Reply #3 - Jun 27th, 2007, 6:13pm
 
you could keep track on the number of branches (or childs) one node has.. if it reaches some value lets say 5, you draw the flower.. sumtin like that..
Re: animating gifs at different times, sizes, loca
Reply #4 - Jun 28th, 2007, 2:09am
 
thanks for the input. I have a few things to try now, keeping my fingers crossed.
Re: animating gifs at different times, sizes, loca
Reply #5 - Jun 28th, 2007, 3:35am
 
sorry, but I still have the same problems, I've moved the count elements (startAngle & timer) out of the parameters for a vine object and into the variables within the the Vine class. I used those as an independent count  for the flowers, but still I get only one of the 5 frames of the flower "blooming". I've included the full code this time (excluding different instances). Thanks for the help.


ArrayList a;
Vine v;
PImage backdrop;

void setup(){
 size(494, 710);
 backdrop= loadImage(
 //"mount.jpg"
 //"wood.jpg"
 //"pinup.jpg"
 //"eden.jpg"
 "swing.jpg"
 //"versailles.jpg"
 );
 background(backdrop);
 frameRate(60);

 a = new ArrayList();
Vine v = new Vine(new CompStore(random((width/4)-85,(width/4)+5),height-100.0), 100.0, 0.01, -1);
a.add(v);
}

void draw(){

 Vine v = (Vine) a.get(0);
 v.fdisplay();
 v.update();
 v.render();

if(v.timeToSplit()){
  v.fdisplay();
  a.remove(0);
  //new vine
  a.add(v.splitOff());
 }

class Vine{
 float vel;
 float timer= random(-PI+1.5707,-0.5);
 CompStore loc = new CompStore();
 CompStore base;
 int dir;
 CompStore startAngle = new CompStore(-PI-1.5707);
 
 //information for flower animation
 float rad;
 float animLocX;
 float animLocY;
 float animBaseX;
 float animBaseY;
 float animRad;
 boolean animSwitch;
 PImage[] flower = new PImage[5];
 int frame = -1;
 
 
 Vine(CompStore location, float radius,  float velocity, int direction){
 vel = velocity;
 rad=radius;
 base = location;
 dir= direction;
 loadImages("flower_a_");
 }

 
 void update(){
   if(startAngle.count<=timer){
      loc.x= rad * cos(startAngle.count)*dir;
      loc.y = rad * sin(startAngle.count);
      startAngle.count+=vel;
   }
 }
 
 void render(){
   pushMatrix();
   translate(loc.x, loc.y);
   ellipseMode(CENTER);
   fill(4, 111, 2, 125);
   smooth();
   noStroke();
   ellipse(base.x, base.y, 0.5, 0.5);
   popMatrix();
   }
 
 boolean timeToSplit(){
   if(startAngle.count<=timer){
     return false;
   }else{
   return true;
   }
 }

 
 Vine splitOff(){
   float pos = random(0.7,0.9);
   float loc0x = base.x + (rad * cos(startAngle.count-1*pos)*dir);
   float loc0y = base.y + (rad * sin(startAngle.count-1*pos));
   float timer = random(-PI+1.5707,-0.5);
   base.x = loc0x;
   base.y = loc0y*pos;
   rad=dist(loc0x, loc0y, base.x, base.y);
   vel = vel*1.05;
   dir = dir*-1;
   return new Vine(new CompStore(base.x,base.y), rad, vel, dir);
   }

/***************flower methods***************************/
void loadImages(String name) {
   for(int i=0; i<5; i++) {
     String imageName = name + "0" + i + ".gif";
     flower[i] = loadImage(imageName);
   }
 }

 void fdisplay(){
   if (startAngle.count>=timer){
   animRad = rad;
   animBaseX = base.x;
   animBaseY = base.y;
   animLocX=loc.x;
   animLocY=loc.y;  
   animSwitch = true;}
   if(frame<4&&animSwitch==true){
   frame++;
   float bigness=animRad*0.5+15;
   pushMatrix();
   translate(animLocX-bigness/2, animLocY-bigness/2);
   image(flower[frame], animBaseX, animBaseY, bigness, bigness);
   popMatrix();
   }else{ frame=-1; animSwitch = false;}
 }

}

/********************************************************/
 public class CompStore{
 public float x;
 public float y;
 public float count;
 
 CompStore(){
   x=0; y=0;
 }
 
 CompStore(float initial_angle){
   count = initial_angle;
 }
 
 CompStore(float x_, float y_){
   x=x_; y=y_;}
 
public CompStore copy() {
   return new CompStore(count);
 }
}

Also, when I try switching animSwitch to -1 and *-1 to switch back and forth the flowers appear with all their frames but right away and at 0,0

thanks again this is destroying my head
Re: animating gifs at different times, sizes, loca
Reply #6 - Jun 29th, 2007, 10:58am
 
can you send me your full application so i can see what do you mean ?

for what i understand you want to create a "tree" that at some point grows flowers instead of branches.. right ?
Re: animating gifs at different times, sizes, loca
Reply #7 - Jul 1st, 2007, 8:17pm
 
Here's the link:

http://eptheater1820.tripod.com/sketch.html

a little gross looking at the moment, but you should get the idea. Also, there will 4 instances of the vine
Re: animating gifs at different times, sizes, loca
Reply #8 - Jul 4th, 2007, 6:13pm
 
hey there. ill check out the code and see what i can find..
sorry if i havent been around.. been having too much work before summer holidays
Page Index Toggle Pages: 1