3 Replies - 232 Views - Last Post: 24 January 2014 - 09:25 AM Rate Topic: -----

#1 Dagmar  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 24-January 14

[Processing] Get image out of array.

Posted 24 January 2014 - 08:32 AM

Hello, I'm having a bit of trouble with getting the last clicked image out of an array. I want to do something like this:

color[] backgrounds = {#e8be55, #ff8827, #eb5051, #00b4cc, #005f6b, #8c6753, #edeaee};
int bgLength = backgrounds.length;
color selectedBackground = backgrounds[backgrounds.length-1];

void setup(){
size(1024, 768);
}

void draw(){
background(selectedBackground);
 createBackgrounds();
}

void createBackground(){
 xOffset = 27;
   yOffset = 167;
  size = 40;
  padding = 5;
  xPos = padding + xOffset;
  yPos = yOffset;
  cols = 4;

  //background(selectedBackground);

  // Grid maken
  for(int i = 0; i < bgLength; i++){
    xPos = xOffset + ((i % cols) * (size + padding));
    yPos = yOffset + ((i / cols) * (size+padding));

    fill(backgrounds[i]);
    // Check of box is aangeklikt  
    if((mouseX >= xPos && mouseX <= xPos+size) && 
       (mouseY >= yPos && mouseY <= yPos+size)) {

      if (mousePressed){
       
        selectedBackground = backgrounds[i];
      }else{ // Hover
        fill(backgrounds[i],127);
      }

      
      }
      rect(xPos, yPos, size, size);
  }
  }
}



This works perfectly, with the images not so.
PImage[] patterns = new PImage[7];
int pLength = patterns.length;
PImage selectedPattern = patterns[patterns.length-1];


void createPatterns(){

  xOffset = 25;
  yOffset = 325;
  size = 54;
  padding = 10;
  xPos = padding + xOffset;
  yPos = yOffset;
  cols = 3;




  for(int j = 0; j < pLength; j++){
    // Grid maanmaken
    xPos = xOffset + ((j % cols) * (size+padding));
    yPos = yOffset + ((j / cols) * (size+padding));




    patronen[j] = loadImage( j + ".png");
    image(patronen[j], xPos, yPos);



    // Check of box is aangeklikt  
     if((mouseX >= xPos && mouseX <= xPos+size) && 
       (mouseY >= yPos && mouseY <= yPos+size)){ 

      if (mousePressed){
        // grid patronen
        xPos = 0;
        yPos = 0;

        //selectedPatroon = patronen[j]

        while( yPos < height ){
          while( xPos < width ){
            patronen[j] = loadImage("groot" + j + ".png");
            image(patronen[j], xPos, yPos); 

            

            xPos += 500;
      }
      yPos +=500;
      xPos = 0;     
     }
     rect(xPos, yPos, size, size);
  }else{
    fill(255,127);
    rect(xPos, yPos, size, size);
  }
}
}
} 



Can someone explain me how to do this with images?
Thanks.

Is This A Good Question/Topic? 0
  • +

Replies To: [Processing] Get image out of array.

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6063
  • View blog
  • Posts: 23,517
  • Joined: 23-August 08

Re: [Processing] Get image out of array.

Posted 24 January 2014 - 09:02 AM

What language are you using?
Was This Post Helpful? 0
  • +
  • -

#3 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10567
  • View blog
  • Posts: 39,118
  • Joined: 27-December 08

Re: [Processing] Get image out of array.

Posted 24 January 2014 - 09:10 AM

The language is called Processing. I think KYA just did a blog entry on it. (I tend to leave these threads in Other Languages as opposed to Java).
Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6063
  • View blog
  • Posts: 23,517
  • Joined: 23-August 08

Re: [Processing] Get image out of array.

Posted 24 January 2014 - 09:25 AM

Oh, there's a language called "Processing". Brilliant.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1