Create an Image Sequence Using Classes

edited March 2015 in How To...

What I'm trying to accomplish looks something like this. However, after trying out several methods there's always something that goes wrong and I just can't figure it out.

PImage happiness;
PImage sorrow;
int x = 250;
int y = 250;

Happiness happy1;
Sorrow sorrow1;

void setup(){
   size(500,500);
   smooth();
   happiness = loadImage ("happiness0.png");
   sorrow = loadImage ("sorrow1.png");

   createMask();
}

void draw (){
  happy1.display();
  sorrow1.display();
  happy1.godname();
  sorrow1.godname();
}

void createMask() {
  happy1 = new Happiness (happiness, x, y);
  sorrow1 = new Sorrow (sorrow, x , y);


}

//Base Class

  abstract class Masks {
  PImage masksImage;
  PVector center;
  PFont font;

  Masks(PImage _image, int x, int y) {
     masksImage = _image;
     center = new PVector (20, 5);
  }

  void display () {
    image(masksImage, center.x, center.y);
  }

  abstract void godname(); {
      font = loadFont("Algerian-20.vlw");
  }

}

//Class 1

  class Happiness extends Masks {
  Happiness(PImage image, int x, int y) {
    super (image, x, y);
  }

  void godname () {
   if (mousePressed == true) {
    textFont(font);
    fill(0);
    text("Eudaemonia", 195, 150);
   }  else {
      fill (#f3f3f4);  
    }
  }
}
Tagged:

Answers

  • There are many logical problems in your classes!
    But main offender is that you're not storing all the parameters passed to the constructors!

  • Thanks for the reply. This is attempt #1 which still isn't working out:

    PImage happiness;
    PImage sorrow;
    int x = 250;
    int y = 250;
    Masks [] masks = new Masks[10];
    
    Happiness happy1;
    Sorrow sorrow1;
    
    void setup(){
       size(500,500);
       smooth();
       happiness = loadImage ("happiness0.png");
       sorrow = loadImage ("sorrow1.png");
    
       createMask();
    
       for (int i = 0; i < masks.length; i ++) {
         masks[i] = new Masks();
       }
    }
    
    void draw (){
     for (int i = 0; i < masks.length; i++) {
      happy1.display();
      sorrow1.display();
      happy1.godname();
      sorrow1.godname();
      }
    }
    
    void createMask() {
      happy1 = new Happiness (happiness, x, y);
      sorrow1 = new Sorrow (sorrow, x , y); 
    }
    
    //Base Class
    abstract class Masks {
      PImage [] masksImage = new PImage[maxImages];
      PVector center;
      PFont font;
      int maxImages = 2;
      int imageIndex = 0;
    
      Masks(int x, int y) {
        center = new PVector (20, 5);
    
         for (int i = 0; i < maskImage.length; i ++) {
           maskImage[i] = loadImage( "mask" + i + ".png");
         }
      }
    
      void display () {
        image(masksImage[imageIndex], center.x, center.y);
      }
    
      void next () {
        imageIndex = (imageIndex + 1) % masksImage.length;
      }
    
      abstract void godname(); {
          font = loadFont("Algerian-20.vlw");
      }    
    }
    
    //Class 1
    class Happiness extends Masks {
      Happiness(PImage image, int x, int y) {
        super (image, x, y);
      }
    
      void godname () {
       if (mousePressed == true) {
        textFont(font);
        fill(0);
        text("Eudaemonia", 195, 150);
       }  else {
          fill (#f3f3f4);  
        }
      }
    
      void next () {
      }
    }
    
Sign In or Register to comment.