dynamically change circle shape
in
Programming Questions
•
2 years ago
Hello,
I would like to influence the shape of a circle based on the vicinity to it of an object, for now the mouse pointer. Depending on the direction from which the pointer is approaching the circle, I would like the circle to bend inwards at that location, unto a maximum.
Ultimately, then also bounce back like an elastic shape. Then after the mouse pointer has arrived inside the circle, I would like the circle to change shape in a similar manner, this time not letting the mouse pointer escape, unless the pointer stretches the circle too far.
I am wondering: does anyone have advice how to go about and work towards this goal? So far, I have arrived at the sketch displayed below, which is a first step, but not quite yet what I have in mind...
Any help welcome! Ciao, Menno.
ps. I used this website to determine how to draw a shape that is almost a circle, using bezier curves. However, maybe there are much better methods to approach this idea?
I would like to influence the shape of a circle based on the vicinity to it of an object, for now the mouse pointer. Depending on the direction from which the pointer is approaching the circle, I would like the circle to bend inwards at that location, unto a maximum.
Ultimately, then also bounce back like an elastic shape. Then after the mouse pointer has arrived inside the circle, I would like the circle to change shape in a similar manner, this time not letting the mouse pointer escape, unless the pointer stretches the circle too far.
I am wondering: does anyone have advice how to go about and work towards this goal? So far, I have arrived at the sketch displayed below, which is a first step, but not quite yet what I have in mind...
Any help welcome! Ciao, Menno.
ps. I used this website to determine how to draw a shape that is almost a circle, using bezier curves. However, maybe there are much better methods to approach this idea?
- float kappa = (4.0 * (sqrt(2.0) - 1.0) / 3.0);
- void setup()
- {
- size(500,500);
- }
- void draw()
- {
- background(255);
- noFill();
- int cradi = 100;
- float ccont;
- ccont = kappa * cradi;
- int cx;
- int cy;
- cx = cy = 250;
- int cx1;
- int cx3;
- int cy1;
- int cy2;
- int cy4;
- cy1 = cy;
- cx1 = cx - cradi;
- cy2 = cy - cradi;
- cy4 = cy + cradi;
- cx3 = cx + cradi;
- int buffer = 10;
- float mouse_dist;
- mouse_dist = sqrt(sq(cx - mouseX) + sq(cy - mouseY));
- if (mouseX > (cx - cradi - buffer) && mouseX < (cx + cradi*2)/2 + cradi/2)
- {
- cx1 = mouseX + buffer;
- }
- if (mouseX < (cx + cradi + buffer) && mouseX > (cx + cradi*2)/2 + cradi/2)
- {
- cx3 = mouseX - buffer;
- }
- if (mouseY > (cy - cradi - buffer) && mouseY < (cy + cradi*2)/2 + cradi/2)
- {
- cy2 = mouseY + buffer;
- }
- if (mouseY < (cy + cradi + buffer) && mouseY > (cy + cradi*2)/2 + cradi/2)
- {
- cy4 = mouseY - buffer;
- }
- bezier(cx1, cy1, cx1, cy - ccont, cx - ccont, cy2, cx, cy2);
- bezier(cx, cy2, cx + ccont, cy2, cx3, cy - ccont, cx3, cy);
- bezier(cx3, cy, cx3, cy + ccont, cx + ccont, cy4, cx, cy4);
- bezier(cx, cy4, cx - ccont, cy4, cx1, cy1 + ccont, cx1, cy1);
- // endShape();
- }
1