Loading...
Logo
Processing Forum

resizing arcs

in Programming Questions  •  1 year ago  
hi, have four arcs with width and height being controlled by mouseX. How can i resize each arc seperatley, at the moment they all move together..

Copy code
  1. int r =90;
  2. float x=100;
  3. float y=100;
  4. float angle;

  5. void setup() {
  6.   size(500, 500);
  7.   smooth();
  8. }

  9. void draw() {
  10.   background(255);
  11.   fill(175);
  12.   float x = mouseX;
  13.   float y = mouseX;
  14.   arc (width/2, height/2, x, y, radians(0), radians(90));
  15.   fill(20);
  16.   arc (width/2, height/2, x, y, radians(90), radians(180));
  17.   fill(60);
  18.   arc (width/2, height/2, x, y, radians(180), radians(270));
  19.   fill(80);
  20.   arc (width/2, height/2, x, y, radians(270), radians(360));
  21. }

Replies(1)

Re: resizing arcs

1 year ago
Not quite sure what you're going after, but here's one idea:

Copy code
  1. void draw() {
  2.   background(255);
  3.   float x = mouseX;
  4.   float y = mouseY;

  5.   float cx = width/2;
  6.   float cy = height/2;
  7.   // convert mouse position to polar coordinates (distance from center, and angle)
  8.   float dx = x-cx;
  9.   float dy = y-cy;
  10.   float d = dist(0,0,dx,dy);
  11.   float a = atan2(dy,dx);
  12.   if (a < 0)
  13.     a += radians(360);
  14.   println(degrees(a));
  15.   if (a < radians(90)) {
  16.     fill(175);
  17.     arc (cx, cy, d*2, d*2, radians(0), radians(90));
  18.   } else if (a  < radians(180)) {
  19.     fill(20);
  20.     arc (cx, cy, d*2, d*2, radians(90), radians(180));
  21.   } else if (a  < radians(270)) {
  22.     fill(60);
  23.     arc (cx, cy, d*2, d*2, radians(180), radians(270));
  24.   } else  {
  25.     fill(80);
  26.     arc (cx, cy, d*2, d*2, radians(270), radians(360));
  27.   }
  28. }

and here's another

Copy code
  1. void draw() {
  2.   background(255);
  3.   float x = mouseX;
  4.   float y = mouseY;

  5.   float cx = width/2;
  6.   float cy = height/2;
  7.   // convert mouse position to polar coordinates (distance from center, and angle)
  8.   float dx = x-cx;
  9.   float dy = y-cy;
  10.   float d = dist(0,0,dx,dy);
  11.   float a = atan2(dy,dx);
  12.   fill(map(a,-PI,PI,0,128));
  13.   arc(cx,cy, d*2, d*2, a-radians(20), a+radians(20));
  14. }