Draw and not draw
in
Programming Questions
•
7 months ago
Hello!
In my code, when you click, a line is drawn with the first point being the center point.
There's an ellipse that is draggable. I want that processing doesn't draw the track of the ellipse, only the lines from the center.
Here's the code.
Thank you!
- //code with help of Casey Reas and Ben Fry
- //declare variables for draggables
- int er = 10;
- boolean hover = false;
- boolean locked = false;
- float newy, newx, ex, ey;
- void setup() {
- size (500, 500);
- smooth();
- rectMode(CENTER);
- ex = 50;
- ey = 420;
- background(255);
- }
- void draw () {
- //draw ellipse
- ellipse (ex, ey, er, er);
- //check if mouse is on the ellipse
- if (mouseX > ex-er && mouseX < ex+er && mouseY > ey-er && mouseY < ey+er) {
- hover = true;
- }
- else {
- hover=false;
- }
- //draw center line
- if (mousePressed==true) {
- line(250,250, mouseX, mouseY);
- }
- }
- //if mouse is clicked inside the ellipse
- void mousePressed() {
- if (hover) {
- locked = true;
- fill (255);
- }
- else {
- locked = false;
- }
- newx = mouseX-ex;
- newy = mouseY-ey;
- }
- //if mouse is dragged while clicking on the object, make it move
- void mouseDragged () {
- if (locked) {
- ex = mouseX - newx;
- ey = mouseY - newy;
- }
- }
- //if mouse released, return to no motion state
- void mouseReleased () {
- locked = false;
- }
1