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 & HelpOther Libraries › Dynamically Resizing Shapes
Page Index Toggle Pages: 1
Dynamically Resizing Shapes (Read 586 times)
Dynamically Resizing Shapes
Oct 7th, 2007, 9:50am
 
Hi,

I was wondering if there is a library or if someone has some code that would help me figure out how to dynamically resize shapes like rect, ecllipse and triangle once they are on the applet? I want the user to be able to modify the shapes as they see fit.

I tried writing the code myself but it's just a mess and isn't doing what I want it to do...

Help please!
Re: Dynamically Resizing Shapes
Reply #1 - Oct 7th, 2007, 4:47pm
 
So I worked on this code last night, and i have it kind of working, so that if you click on the small red boxes and drag them they change accordingly. However, the process isn't as smooth as I'd like it to be.

Could someone see a way to fix it? To make the drag smoother?

float x=100;
float y=100;
float w = 30;
float h = 30;

void setup() {
 size(230, 230);
 frameRate(30);

 refresh();
}

void draw() {
 fill(255);

 if (mousePressed) {
   //test to see if you touched to top middle mini rect
   if (mouseX >= x+w/2-3 && mouseY >= y-3 && mouseX <= x+w/2+3 && mouseY <= y+3) {
     println("You have touched the top mini rect!");

     h = h+(y-mouseY);
     y = mouseY;
   }
   
   //test to see if you touched the bottom left corner mini rect
   if (mouseX >= x-3 && mouseY >= y+h-3 && mouseX <= x+3 && mouseY <= y+h+3) {
     println ("You have touched the bottom left corner mini rect!");
     
     w = w+(x-mouseX);
     h = h+(mouseY-(h+y));
     x = mouseX;
   }
   
   refresh();
 }
}


void refresh() {
 fill(100);
 rect(0,0,230, 230);

 fill(255);
 rect(x, y, w, h);

 fill(255,0,0);
 rect(x+w/2-3, y-3, 6, 6);
 rect(x-3, y+h-3, 6, 6);

 fill(0);
 rect(x-3,y-3, 6, 6);
 rect(x-3, y+h/2-3, 6, 6);
 rect(x+w-3,y-3, 6, 6);
 rect(x+w/2-3, y+h-3, 6, 6);
 rect(x+w-3, y+h-3, 6, 6);
 rect(x+w-3, y+h/2-3, 6, 6);
}
Page Index Toggle Pages: 1