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 & HelpPrograms › How to position an image
Page Index Toggle Pages: 1
How to position an image ? (Read 817 times)
How to position an image ?
May 9th, 2010, 2:03pm
 
Hi , i got this sketch  :

...

http://openprocessing.org/visuals/?visualID=9579


Is a simple sketch where the rects grow as you hoover over them.



I want that instead of a rect , there was an image .

But the image function only has  width and height and format :

PImage()
PImage(width, height)
PImage(width, height, format)
PImage(img)




How do i tell processing where to position the image

Can i recycle my code , where i use rects


Code:

int borde = 20;
int hoover = 5;
int borde_hoover;
void setup (){

size (600,600);
smooth();
background (255);
}

void draw (){
background (255);
drawR_1 (width/2-borde,width/4,height/4);
drawR_2 (width/2-borde,width-width/4,height/4);
drawR_3 (width/2-borde,width/4,height-height/4);
drawR_4 (width/2-borde, width-width/4,height-height/4);

}



// functions




void drawR_1 ( int tamanio, int rx_pos, int yx_pos ){
 fill (0);
 rectMode ( CENTER);
 noStroke ();
   if (mouseX > borde_hoover && mouseX < width/2-borde_hoover && mouseY > borde && mouseY < height/2-borde_hoover ){

    tamanio += hoover ;
  }
    else{
tamanio -=hoover ;

  }
   
   rect ( rx_pos, yx_pos , tamanio, tamanio);
}


void drawR_2 ( int tamanio, int rx_pos, int yx_pos ){
 fill (0);
 rectMode ( CENTER);
 noStroke ();
   if (mouseX > width/2+borde_hoover && mouseX < width-borde_hoover && mouseY > borde && mouseY < height/2-borde_hoover ){

    tamanio += hoover ;
  }
    else{
tamanio -=hoover ;

  }
   
   rect ( rx_pos, yx_pos , tamanio, tamanio);
}

void drawR_3 ( int tamanio, int rx_pos, int yx_pos ){
 fill (0);
 rectMode ( CENTER);
 noStroke ();
   if (mouseX > borde && mouseX < width/2-borde_hoover && mouseY > height/2 && mouseY < height-borde_hoover ){

    tamanio += hoover ;
  }
    else{
tamanio -=hoover ;

  }
   
   rect ( rx_pos, yx_pos , tamanio, tamanio);
}

void drawR_4 ( int tamanio, int rx_pos, int yx_pos ){
 fill (0);
 rectMode ( CENTER);
 noStroke ();
   if (mouseX > width/2+borde_hoover && mouseX < width- borde && mouseY > height/2+borde_hoover && mouseY < height-borde_hoover ){

    tamanio += hoover ;
  }
    else{
tamanio -=hoover ;

  }
   
   rect ( rx_pos, yx_pos , tamanio, tamanio);
}



Re: How to position an image ?
Reply #1 - May 9th, 2010, 2:52pm
 
PImage(...) is the constructor of a PImage object, image() is the function to draw, and that gives you x/y/width/height options
Re: How to position an image ?
Reply #2 - May 9th, 2010, 3:08pm
 
Quote:
PImage(...) is the constructor of a PImage object, image() is the function to draw, and that gives you x/y/width/height options



awesome !!!


i got it working !!!


thanx! Grin Grin Grin Grin Grin Grin
Page Index Toggle Pages: 1