Hi , i got this sketch.
http://openprocessing.org/visuals/?visualID=9579It has 4 very similar functions. they just draw an Image or rects , and make them grow as you hoover them.
But when i run my sketch , i can see in the activity monitor , my cpu gets a lotta work , for this simple sketch.
i think the problem is that it is re drawing the image over and over, and this might be slowing it down , is there a more optimal way to do this
so any ideas on how to optimize this
thanx !
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);
imageMode(CENTER);
noStroke ();
if (mouseX > borde_hoover && mouseX < width/2-borde_hoover && mouseY > borde && mouseY < height/2-borde_hoover ){
tamanio += hoover ;
}
else{
tamanio -=hoover ;
}
PImage b;
b = loadImage("javi_img_01.jpg");
image (b , 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);
}