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.
IndexDiscussionExhibition › elastic sides
Page Index Toggle Pages: 1
elastic sides (Read 1425 times)
elastic sides
Feb 5th, 2006, 3:00am
 
Heres something i made, and im very proud of it Smiley

http://www.codetree.org/artwork/art.php?id=184

heres the code:
Code:


int numberOfPoints = 4;
int maxPoints = 12;
int radius = 50;

boolean pointsVisible = true;
int global_size = 20;

punto voido = new punto(0, 0);
punto currentDragged = voido;

class punto {
 int x, y;
 punto (int _x, int _y) {
   x = _x;
   y = _y;
 }
 void update (boolean visible) {
   if(visible){
     ellipse(x, y, global_size, global_size);
   }
   if(mousePressed && currentDragged==voido){
     if(int(sqrt(pow(mouseX-x, 2)+pow(mouseY-y, 2)))<global_size/2){
       currentDragged = this;
     }
   }
 }
}
class dot {
 float xSpd=0, ySpd=0,x ,y;
 punto a, b;
 dot(punto uno, punto dos){
   a = uno;
   b = dos;
   setInitialPos();
 }
 dot(){
 }
 void setInitialPos(){
   x=(a.x+b.x)/2;
   y=(a.y+b.y)/2;
 }
 void update(){
   xSpd += ((a.x+b.x)/2-x)/20;
   ySpd += ((a.y+b.y)/2-y)/20;
   xSpd *= .92;
   ySpd *= .92;
   x += xSpd;
   y += ySpd;
 }
}

void mouseDragged() {
 currentDragged.x = mouseX;
 currentDragged.y = mouseY;
}
void mouseReleased(){
 currentDragged = voido;
 if(mouseButton == CENTER){
   noLoop();
 } else if(mouseButton == RIGHT) {
   loop();
 }
}

import processing.opengl.*;


punto[] puntos = new punto[maxPoints];
dot[] curvas = new dot[maxPoints];

   
void setup() {
 size(800, 600, OPENGL);
 framerate(80);
 smooth();
 float preRadian=TWO_PI/numberOfPoints;
       
 for(int index=0; index<maxPoints; index++){
   //puntos
   float radian=index*preRadian;
   puntos[index] = new punto (int(cos(radian)*radius+width/2), int(sin(radian)*radius+height/2));
 }
 for(int index=0; index<maxPoints-1; index++){
   //curvas
   curvas[index] = new dot ();
 }
 curvas[maxPoints-1] = new dot();
 //
 reOrderCurves();
}

void reOrderCurves() {
 for(int index=0; index<numberOfPoints-1; index++){
   //curvas
   curvas[index].a = puntos[index];
   curvas[index].b = puntos[index+1];
 }
 curvas[numberOfPoints-1].a = puntos[numberOfPoints-1];
 curvas[numberOfPoints-1].b = puntos[0];
}
int currentRadius = radius;
void keyPressed() {
 if(keyCode == ENTER){
   reOrderCircles(int(random(min(width, height)/2)));
 } else if(keyCode == 32){//code 32 == SPACE
   pointsVisible = ! pointsVisible;
 } else if(key == '-'){
   global_size=max(global_size-5, 5);
 } else if(key == '+'){
   global_size=min(global_size+5, 50);
 } else if(key == '<'){
   numberOfPoints=max(numberOfPoints-1, 2);
   reOrderCurves();
   //reOrderCircles(currentRadius);
 } else if(key == '>'){
   numberOfPoints=min(numberOfPoints+1, maxPoints);
   reOrderCurves();
   reOrderCircles(currentRadius);
 }
}
void reOrderCircles(int radius){
 currentRadius = radius;
 float preRadian=TWO_PI/numberOfPoints;
 for(int index=0; index<numberOfPoints; index++){
   float radian=index*preRadian;
   puntos[index].x=int(cos(radian)*radius+width/2);
   puntos[index].y=int(sin(radian)*radius+height/2);
 }
}

void draw () {
 background(100);
 //
 for(int index=0; index<numberOfPoints; index++){
   //beziers (beziers behind circles);
   bezier(curvas[index].a.x, curvas[index].a.y, curvas[index].x, curvas[index].y, curvas[index].x, curvas[index].y, curvas[index].b.x, curvas[index].b.y);
 }
 for(int index=0; index<numberOfPoints; index++){
   //updates (circles in front of beziers);
   curvas[index].update();
   puntos[index].update(pointsVisible);
 }
}

/**
<PRE>
 <H3>Creates a polygon, with draggable vertexs, whose sides are elastic.</H3>
<B>Controls:</B>
 >        creates a new point for the polygon.
 <        removes a point.
 
 +        makes the draggable area of the points bigger.
 -        makes the draggable area smaller.
 
 SPACE    hides/shows the draggable area of the points.
 
 ENTER    resets the points (with a random radius).
</PRE>
*/



plz, give me some feedback Wink
Re: elastic sides
Reply #1 - Feb 5th, 2006, 11:47am
 
Very nice Smiley
Re: elastic sides
Reply #2 - Feb 6th, 2006, 6:37pm
 
thankyou Smiley

¿any more feedback?
Re: elastic sides
Reply #3 - Feb 10th, 2006, 9:42am
 
nice work!
Try making a slingshot out of it, or perhaps add a tool where the user can add vertices, create his own stringy polygons or something.. add _more_ interactivty, and start playing with some 3d perhaps..?

-seltar
Page Index Toggle Pages: 1