Blah
November 20, 2021, 3:58pm
1
I need the lines drawn to be saved and match up to form an overall route. Really confused as to what’s missing.
float cx; // x coordinate of point 1
float cy; // x coordinate of point 1
int lastClickX = -1;
int lastClickY = -1;
float x = 0;
void setup() {
size(700, 700);
}
void mousePressed() {
cx = mouseX;
cy = mouseY;
redraw();
}
void mouseReleased() {
if(lastClickX>=0 && lastClickY>=0) line(mouseX,mouseY,lastClickX,lastClickY);
lastClickX = mouseX;
lastClickY = mouseY;
}
void draw() {
background(0, 0, 100);
ellipse(cx, cy, 20, 20);
stroke(255);
line(cx, cy, mouseX, mouseY);
line(mouseX,mouseY,lastClickX,lastClickY);
line (pmouseX, pmouseY, mouseX, mouseY);
println ();
float distance = dist(cx, cy, mouseX, mouseY);
textSize(60);
text(""+distance, 40, 500);
}
Chrisir
November 20, 2021, 5:26pm
2
Do you want to save the lines (as data, eg start and end point) on the hard drive?
Blah
November 20, 2021, 5:28pm
3
Hi! Thank you for your reply
I’d just like the lines to appear on the screen. As in, I would like to draw a point, have that stay on screen and then be able to draw the next line. i.e. Point A – Point B – Point C
Does that make sense?
Blah
November 20, 2021, 5:56pm
5
Woah, I really am a beginner
The points work! But it seems that the background was hiding some kind of wild lines being drawn. I assume it has something to do with the framerate? Or something in that direction?
glv
November 20, 2021, 6:04pm
6
Hello,
There are resources here:
As a beginner you should be take a look the tutorials and look up the references for all the elements of your code.
:)
Chrisir
November 20, 2021, 6:14pm
7
instead of getting rid of background you can really store the lines (start points) in an ArrayList
example
float cx; // x coordinate of point 1
float cy; // x coordinate of point 1
int lastClickX = -1;
int lastClickY = -1;
float x = 0;
ArrayList<PVector> list = new ArrayList();
void setup() {
size(700, 700);
}
void mousePressed() {
cx = mouseX;
cy = mouseY;
list.add(new PVector(mouseX, mouseY));
// redraw();
}
void mouseReleased() {
if (lastClickX>=0 && lastClickY>=0)
{
//line(mouseX, mouseY, lastClickX, lastClickY);
// list.add(new PVector(mouseX, mouseY));
}
lastClickX = mouseX;
lastClickY = mouseY;
}
void draw() {
background(0, 0, 100);
ellipse(cx, cy, 20, 20);
stroke(255);
line(cx, cy, mouseX, mouseY);
line(mouseX, mouseY, lastClickX, lastClickY);
line (pmouseX, pmouseY, mouseX, mouseY);
println ();
float distance = dist(cx, cy, mouseX, mouseY);
textSize(60);
text(""+distance, 40, 500);
for (PVector pv : list) {
ellipse(pv.x, pv.y,
8, 8);
//line(pv.x, pv.y,.....);
}
}
1 Like