-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathedit.js
54 lines (46 loc) · 1.05 KB
/
edit.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const Paths = [];
class Segment{
constructor(_x1,_y1,_x2,_y2){
this.x1 = _x1;
this.y1 = _y1;
this.x2 = _x2;
this.y2 = _y2;
}
}
class Point{
constructor(_x,_y){
this.x = _x;
this.y = _y;
}
}
class Path{
constructor(){
this.Points = [];
}
Draw(){
strokeWeight(2);
stroke(255,255,255);
let frst,prev;
for(let i in this.Points){
if(!frst) frst = this.Points[i];
if(prev){
line(prev.x,prev.y,this.Points[i].x,this.Points[i].y);
}
prev = this.Points[i];
}
line(prev.x,prev.y,frst.x,frst.y);
}
}
function PathToSegments(path){
Segments = [];
let frst,prev;
for(let i in path.Points){
if(!frst) frst = path.Points[i];
if(prev){
Segments.push(new Segment(prev.x,prev.y,path.Points[i].x,path.Points[i].y));
}
prev = path.Points[i];
}
Segments.push(new Segment(prev.x,prev.y,frst.x,frst.y));
return Segments;
}