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 & HelpSyntax Questions › scale an image ¿
Page Index Toggle Pages: 1
scale an image ?¿ (Read 596 times)
scale an image ?¿
Mar 6th, 2006, 8:38pm
 
Hey, I have been trying the example with the name "sacale" (http://processing.org/learning/examples/scale.html).
I would like to do the same as the black square with an image. I know how to load it an include it in the code but when I execute the code, the image isn't in the center. It's because the coordenates of the image are the left-up corner an de image is inverted.... This is the code

float a = 0.0;
float s = 0.0;
PImage im;
void setup()
{
 size(200,200);
 noStroke();
 rectMode(CENTER);
 framerate(30);
}

void draw()
{
 background(102);
 im=loadImage("mole.gif");
 a = a + 0.04;
 s = cos(a)*2;
 
 translate(width/2, height/2);
 scale(s);
 image(im, 0,0);  
}


So I don't know if its posible to do what I want.

Thanks
Re: scale an image ?¿
Reply #1 - Mar 6th, 2006, 9:01pm
 
I get the feeling there's a better way to do this, but this works...

Just make sure s is always positive, then, when it would be negative, shift the picture over to the left proportional to s:

float a = 0.0;
float s = 0.0;
PImage im;
void setup()
{
 size(200,200);
 noStroke();
 rectMode(CENTER);
 framerate(30);
}

void draw()
{
 background(102);
 im=loadImage("mole.gif");
 a = a + 0.04;
 s = cos(a)*2;
 if (s<0) {
    s *= -1;
    translate(-im.width*s,0);
 }
 translate(width/2, height/2);
 scale(s);
 image(im, 0,0);  
}
Re: scale an image ?¿
Reply #2 - Mar 6th, 2006, 9:08pm
 
Oh, if you want it centred like in the example:

float a = 0.0;
float s = 0.0;
PImage im;
void setup()
{
 size(200,200);
 noStroke();
 rectMode(CENTER);
 framerate(30);
}

void draw()
{
 background(102);
 im=loadImage("mole.gif");
 a = a + 0.04;
 s = cos(a)*2;
 if (s<0) {
    s *= -1;
 }
 translate((width/2)-((im.width*s)/2), height/2-((im.height*s)/2));
 scale(s);
 image(im, 0,0);  
}
Re: scale an image ?¿
Reply #3 - Mar 6th, 2006, 9:10pm
 
I knew there was a simpler way.

float a = 0.0;
float s = 0.0;
PImage im;
void setup()
{
 size(200,200);
 noStroke();
 rectMode(CENTER);
 framerate(30);
}

void draw()
{
 background(102);
 im=loadImage("mole.gif");
 a = a + 0.04;
 s = cos(a)+1;
 translate((width/2)-((im.width*s)/2), height/2-((im.height*s)/2));
 scale(s);
 println(s);
 image(im, 0,0);  
}
Re: scale an image ?¿
Reply #4 - Mar 6th, 2006, 9:39pm
 
This is nicer cos it keeps the same phase: (I'll stop playing with it now)

float a = 0.0;
float s = 0.0;
PImage im;
void setup()
{
 size(200,200);
 noStroke();
 rectMode(CENTER);
 framerate(30);
}

void draw()
{
 background(102);
 im=loadImage("mole.gif");
 a = a + 0.04;
 s = cos(a)*cos(a);
 translate((width/2)-((im.width*s)/2), height/2-((im.height*s)/2));
 scale(s);
 println(s);
 image(im, 0,0);  
}
Re: scale an image ?¿
Reply #5 - Mar 6th, 2006, 11:03pm
 
ejjejej Thanks. Nice, very nice
Page Index Toggle Pages: 1