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 but maintain in the center
Page Index Toggle Pages: 1
scale but maintain in the center (Read 636 times)
scale but maintain in the center
Jun 2nd, 2009, 8:10am
 
hello i need to scale an sphere using iteration, but i need that in each iteration the new scaled sphere appears in the center. How can i do that?


there there are some pics so you can understand better
this is what i need to do:
http://fotosupload.com/mostrar.php?imagen=FuD89406_centroooo.png

and this is what my code is doing:

http://www.fotosupload.com/mostrar.php?imagen=FuD89408_no_center.png


any idea? I also need to do the same with lines


here is my code:


  for (int i=0 ; i < 5 ; i ++) {
      pushMatrix ();
      translate(40,22 );
      pushMatrix ();
       translate(i * 3, 0 );
      scale(1 , 1 + i);
      ellipse(22, 22, 22, 22);
     //line(0.5  , 0.5 ,  0.5 ,  6 );
      popMatrix();
      popMatrix();
}
Re: scale but maintain in the center
Reply #1 - Jun 2nd, 2009, 10:15am
 
try scaling before the translate (the way you have it the offset from 0,0 is also being scaled)
Re: scale but maintain in the center
Reply #2 - Jun 2nd, 2009, 10:31am
 
koogy ive tried that but it doesnt work!!!
Re: scale but maintain in the center
Reply #3 - Jun 2nd, 2009, 12:02pm
 
The problem is that you used coordinates in ellipse() call: when you do a transformation, you should always use 0, 0 coordinates.
Code:
size(500, 500);
smooth();
for (int i=0 ; i < 5 ; i ++) {
pushMatrix();
translate(100, 100);
scale(1, 1 + i);
translate(i * 8, 0);
ellipse(0, 0, 22, 22);
popMatrix();
}

Also there is no need for two push/popMatrix.
Re: scale but maintain in the center
Reply #4 - Jun 2nd, 2009, 12:27pm
 
amazing philho, many thanks!!!!
Page Index Toggle Pages: 1