random image size

edited June 2017 in How To...

how to change each image size randomly like twinkle stars?

Tagged:

Answers

  • Look at PImage resize

    look at random

  • edited June 2017

    This is an idea of how you could do it. Don't forget to check the reference to understand the concept below. Note code below hasn't been tested.

    Kf

    //ASSUMING original image has a size of 500 in width    
    final int[] SIZES={450,550};
    int dx=2;
    
    
    void setup(){   ... }
    
    void draw(){
       //Next applies resize every 5 frames
       if(frameCount%5==0){
         resizeImage();
      }
    
       ...
       ...  OTHER draw functions
       ...
    }
    
    void resizeImage(){
      int csize=img.width;
       csize+=dx;
    
      //NEXT: reverts direction of resizing when up/low limit is reached
      if(csize<SIZES[0] || csize>SIZES[1] ){   //EDIT
          dx=-dx;
       }  
    
       img.resize(csize,0);
    }
    
  • Why this sentence "sizes cannot be resolved to a variable" appears on the screen ?

  • It was untested code. I edited the post and fixed the problem.

    Kf

Sign In or Register to comment.