bnagle
YaBB Newbies
Offline
Posts: 11
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