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 & HelpSyntax Questions › float / sketch image size problem
Page Index Toggle Pages: 1
float / sketch image size problem (Read 377 times)
float / sketch image size problem
Apr 23rd, 2007, 1:53pm
 
hi,

This is a code i've put together from other examples. what i want to do is have two different series of images (animations) respond to different data (and eventually three or more different series).
my problem is that my images are formatted for size(600,399) but the code im using is formatted for a different size, and i cant figure out where to change it. i have a feeling it has to do with the width and getWidth bits in there but i dont quite understand them.
eventually if all goes well the images will be responding to an ardunio board with number values, so im wondering what to do about the float part.

any suggestions? heres my code. thanks

 


Balloons series1, series2; //series3;  
float xpos, ypos;

   
void setup()
{

 size(300, 399);
 //frameRate(1);
 
 series1 = new Balloons("balloon", 5);
 series2 = new Balloons("ball", 5);
 //series3 = new Balloons("balloo", 5);
 
}
 

void draw()
 {
 float difx = mouseX - xpos;
 if(abs(difx) > 1.0) {
xpos = constrain(xpos, 0, width);
 }
 
if(mousePressed) {
 frameRate(7);
 series1.display(xpos-series1.getWidth()/2, ypos);
 }

else {
 frameRate(3);
 series2.display(xpos-series1.getWidth()/2, ypos);
 }
 
//else{
 //frameRate(1);
//series3.display(xpos-series1.getWidth()/2, ypos);
//}
}

class Balloons
{
 PImage[]bal;
 int frame;
 int numFrames;
 
 Balloons(String imageName, int frameCount){
   numFrames = frameCount;
   bal = new PImage[numFrames];
   loadImages(imageName);
 }
 
  void loadImages(String name) {
   for(int i=0; i<numFrames; i++) {
     String imageName = name + ((i < 4) ? "" : "") + i + ".JPG";
     bal[i] = loadImage(imageName);
   }
  }
 void display(float xpos, float ypos)
 {
   frame = (frame+1)%numFrames;
   image(bal[frame], xpos, ypos);
 }
 
 int getWidth() {
   return bal[0].width;
 }
}


Page Index Toggle Pages: 1