Loading...
Processing Forum
Recent Topics
All Forums
Screen name:
dsfire
dsfire's Profile
1
Posts
2
Responses
0
Followers
Activity Trend
Last 30 days
Last 30 days
Date Interval
From Date :
To Date :
Go
Loading Chart...
Posts
Responses
PM
Show:
All
Discussions
Questions
Expanded view
List view
Private Message
Draw and not draw
[4 Replies]
07-Mar-2013 05:33 PM
Forum:
Programming Questions
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;
}
«Prev
Next »
Moderate user : dsfire
Forum