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.
IndexProcessing DevelopmentLibraries,  Tool Development › Simple helper tool for tiny scalable button
Page Index Toggle Pages: 1
Simple helper tool for tiny scalable button (Read 431 times)
Simple helper tool for tiny scalable button
May 21st, 2008, 6:37pm
 
I was making a simple button interface and found myself handcoding the relative points, so I made a primitive tool to address this.

The program will print a short code to draw the shape using vertex function.

/////////////////////////////////////////
import java.util.Iterator;

ArrayList points;

void setup(){
 size(640,480);
 frame.setResizable(true);
 cursor(CROSS);
 points = new ArrayList();
}

void draw(){
 background(200);
 Iterator ite =  points.iterator();

 beginShape();
 
 while(ite.hasNext()){
   Vector v = (Vector)ite.next();
   float x = width*v.x;
   float y = width*v.y;

   vertex(x, y);
 }
 
 endShape();
}

class Vector{
 public float x;
 public float y;
}

void mousePressed(){
 if (mouseButton == RIGHT){
   // erase last point
   int i = points.size();
   if (i > 0){
     points.remove(i-1);
   }
   println("****point deleted. the new code is:");
   Iterator ite =  points.iterator();
   while(ite.hasNext()){
     Vector v = (Vector)ite.next();
     println("vertex("+v.x+"*f,"+v.y+"*f);");
   }
 }else{
   // add a point
   Vector v = new Vector();
   v.x = (float)mouseX/(float)width;
   v.y = (float)mouseY/(float)width;
   points.add(v);
   println("vertex("+v.x+"*f,"+v.y+"*f);");
 }
}
/////////////////////////////////////////

Maybe this has been done before in the forum, but I couldn't find it immediately, so I posted this cookbook method.  
Page Index Toggle Pages: 1