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 & HelpPrograms › arc interaction
Page Index Toggle Pages: 1
arc interaction (Read 737 times)
arc interaction
Apr 3rd, 2010, 10:00am
 
Hi, I'm trying to make a mouse interactive project with some arc.
This is the code I wrote:

int diam=80;
int x=-diam/2;
int y=0;
float transX=120;
float transY=60;

void setup () {
 
 size (400,400);
 smooth();
}
void draw () {
 background (255);
 strokeWeight(1.5);
 stroke(0);
 fill(255,0,0);
 float theta = PI/2*mouseX / width;
 
 pushMatrix();
 translate (transX,transY);
 rotate (-theta);
 ellipseMode(CORNER);
 arc(x, y, diam, diam, PI+HALF_PI, TWO_PI+HALF_PI);
 line(0,0, 0,diam);
 popMatrix();
 
 pushMatrix();
 translate (transX,transY);
 rotate (theta);
 ellipseMode(CORNER);
 arc(x,y,diam,diam, PI/2,PI+HALF_PI);
 line(0,0, 0,diam);
 popMatrix();
 
 pushMatrix();
 translate (transX,transY+2*diam);
 rotate (theta);
 ellipseMode(CORNER);
 arc(x,y-diam, diam, diam, PI+HALF_PI, TWO_PI+HALF_PI);
 line(0,-diam, 0,0);
 popMatrix();

 pushMatrix();
 translate (transX,transY+2*diam);
 rotate (-theta);
 ellipseMode(CORNER);
 arc(x,y-diam,diam,diam, PI/2,PI+HALF_PI);
 line(0,-diam, 0,0);
 popMatrix();
}  

As you can see the mouseX variation open and close the arcs. I'm trying to make the two lower arcs united with the first two.  Undecided
Anybody can help me?
Re: arc interaction
Reply #1 - Apr 4th, 2010, 12:39pm
 
Quote:
int diam=80;
int x=-diam/2;
int y=0;
float transX=120;
float transY=100;

void setup () {
 
 size (400,400);
 smooth();
}
void draw () {
 background (255);
 strokeWeight(1.5);
 stroke(0);
 fill(255,0,0);
 float theta = PI/2*mouseX / width;
 
 pushMatrix();
 translate (transX,transY);
  translate(0,-diam*cos(theta));
 rotate (-theta);
 ellipseMode(CORNER);
 arc(x, y, diam, diam, PI+HALF_PI, TWO_PI+HALF_PI);
 line(0,0, 0,diam);
 popMatrix();
 
 pushMatrix();
 translate (transX,transY);
  translate(0,-diam*cos(theta));
 rotate (theta);
 ellipseMode(CORNER);
 arc(x,y,diam,diam, PI/2,PI+HALF_PI);
 line(0,0, 0,diam);
 popMatrix();
 
 pushMatrix();
 translate (transX,transY);
  translate(0,diam*cos(theta));
 rotate (theta);
 ellipseMode(CORNER);
 arc(x,y-diam, diam, diam, PI+HALF_PI, TWO_PI+HALF_PI);
 line(0,-diam, 0,0);
 popMatrix();

 pushMatrix();
 translate (transX,transY);
 translate(0,diam*cos(theta));
 rotate (-theta);
 ellipseMode(CORNER);
 arc(x,y-diam,diam,diam, PI/2,PI+HALF_PI);
 line(0,-diam, 0,0);
 popMatrix();
}  



I think that's what you want.
Re: arc interaction
Reply #2 - Apr 4th, 2010, 5:45pm
 
Hey, Thank you for the answer!!! It's a good solution. Today i re-write the code from the start and i find another way to do it. By the way thank's a lot!!!

void setup() {
size(500,500);
smooth();
ellipseMode(CORNER);
fill(255,0,0);
}

void draw() {
 
background (255);
float a =   PI/2*mouseX / width;
int d = 100;
int x =100, y = 100;


pushMatrix();
 
translate(x,y);
rotate(-a);
line(0,0, -d,0);
arc(-d,-d/2,d,d,PI,TWO_PI);


translate(0,0);
rotate(2*a);
line(0,0, d,0);
arc(0,-d/2,d,d,PI,TWO_PI);


translate(d,0);
rotate(PI+(-2*a));
line(0,0, d,0);
arc(0,-d/2,d,d,PI,TWO_PI);


translate(d,0);
rotate(2*a);
line(0,0, d,0);
arc(0,-d/2,d,d,PI,TWO_PI);


popMatrix ();
}
Page Index Toggle Pages: 1