Loading...
Logo
Processing Forum
Hello,

My ultimate goal is to be able to animate the shrinking of a rectangle such that the bottom left corner remains stationary.

It seems like the easiest way to do this would be to have the rectangle be drawn from that corner, but I'm having difficulty accomplishing that.

Thoughts?

Thanks,
jhs

Replies(4)

Have a look at rectMode(CORNERS).  I reckon that might offer a solution...
I have looked at rectMode(CORNERS) previously.
This draws the top left and bottom right corners of the rectangle in the form (x,y,x,y)

It seems like it would be possible to generate the same effect using this method, but the calculation involved is a little beyond me, especially if there is an easier way to accomplish the task.

EDIT:
Or maybe not, it just looked too intimidating so I didn't bother, but after playing with it for a minute I have figured out that it shouldn't be too hard. Thanks

The syntax rectMode(CORNERS) uses the first and second parameters of rect() to set the location of one corner and uses the third and fourth parameters to set the opposite corner.
My added emphasis.  The language in the Reference is usually fairly specific - and if it doesn't specify top-left corner then you can assume that it can be any corner ;)

Copy code
  1. int topRightX = 300;
  2. int topRightY = 100;

  3. void setup() {
  4.   size(400,400);
  5.   background(0);
  6.   fill(#ff9900);
  7.   stroke(#ffffff);
  8.   rectMode(CORNERS);
  9. }

  10. void draw() {
  11.   background(0);
  12.   rect(100,300, topRightX, topRightY);   
  13.   topRightX --;
  14.   topRightY ++;
  15. }
This is what I'm using, but it's terribly complicated when I try to make changes to the position of the rectangle.

A good deal of this complication comes from the fact that I'm stopping the rectangle's shrinking at 25x25, which would be much easier if I could just specify width and height.