repeat shapes/imgs in random places

edited December 2013 in How To...

Hello there,

first of all I am sorry if this is a question that is already solved somewhere here in this forum, but I am a newbie in processing and I don't know where or for what I should search to find a good result.

So but here is my question. I have 2 SVG files for the beginning and I want the program to place them in a random position and random angle, BUT not just once. I want the program to repeat it a few times so that I can get a nice pattern. Is there a simple was to achieve this?

Thank you already guys :D

Prono

Answers

  • You can use this code, but then you can't call background() in draw().

    PImage p;
    int number = 5;
    float x;
    float y;
    float a;
    
    void setup() {
      size(400, 400);
      p = loadImage("image.png"); //.svg, in your case.
      strokeWeight(5);
      imageMode(CENTER);
      for (int i = 0; i < number; i++) {
        x = random(width);
        y = random(height);
        a = random(359);
        pushMatrix();
        translate(x, y);
        rotate(a);
        image(p, 0, 0, 150, 130);
        popMatrix();
      }
    }
    

    -- MenteCode

  • edited December 2013

    If you DO, however, need to call background() in draw(), then you'll have to use a different code, as that covers all images created in setup(). Otherwise, the code above is the simplest way.

    I forgot to mention this in the last post. Change the number variable to change the amount of pictures shown.

Sign In or Register to comment.