-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdraw.js
More file actions
128 lines (91 loc) · 2.95 KB
/
Copy pathdraw.js
File metadata and controls
128 lines (91 loc) · 2.95 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
//Salesman's Tackle v2 by Alpharou. draw.js
function draw() {
//Draw background with cartesian lines and canvas rectangle.
strokeWeight(1);
background(colour.background);
stroke(colour.mscllns);
line(width/2, 0, width/2, height);
line(0, height/2, width, height/2);
noFill();
rect(0, 0, width -1, height -1);
if (tackleWorking) {
strokeWeight(24);
stroke(colour.red);
noFill();
rect(0, 0, width, height);
strokeWeight(1);
stroke(colour.mscllns);
};
//Trace line between two points if drawConnections == true.
if (drawConnections == true) {
for (var i = 0; i < cities.length-1; i++) {
stroke(colour.points);
strokeWeight(1);
line(cities[i].x, cities[i].y, cities[i+1].x, cities[i+1].y);
};
//Line that closes the loop when set that way in getLoop.
if (getLoop) {
line(cities[0].x, cities[0].y, cities[cities.length-1].x, cities[cities.length-1].y);
};
};
for (var i = 0; i < cities.length; i++) {
//Make the outer ring.
fill(colour.background);
stroke(colour.points);
ellipse(cities[i].x, cities[i].y, screenScale.val*30, screenScale.val*30);
//Print the order of that point if it is already sorted.
switch (drawConnections) {
default:
//Make the outer ring.
fill(colour.background);
stroke(colour.points);
ellipse(cities[i].x, cities[i].y, screenScale.val*30, screenScale.val*30);
noStroke();
fill(colour.points);
ellipse(cities[i].x, cities[i].y, screenScale.val*20, screenScale.val*20);
break;
case true:
//Make the outer ring.
fill(colour.background);
strokeWeight(1);
stroke(colour.points);
ellipse(cities[i].x, cities[i].y, screenScale.val*30, screenScale.val*30);
noStroke();
fill(colour.points);
textAlign(CENTER, CENTER);
textSize(screenScale.val*20);
text(i + 1, cities[i].x, cities[i].y);
break;
};
};
if (drawMouseCoords == true) {
switch (screenScale.mob) {
default:
fill(colour.mscllns);
noStroke();
ellipse(mouseX, mouseY, screenScale.val*8, screenScale.val*8);
textSize(screenScale.val*15);
text(floor(cartesianTransform(mouseX, 'x'))
+ ", "
+ floor(cartesianTransform(mouseY, 'y')),
mouseX + screenScale.val*10 + 10,
mouseY + screenScale.val*10 + 10);
break;
case true:
var lastMouseX = mouseX
var lastMouseY = mouseY
noFill();
stroke(colour.mscllns);
ellipse(lastMouseX, lastMouseY, screenScale.val*30, screenScale.val*30);
fill(colour.mscllns);
noStroke();
textSize(screenScale.val*15);
text(floor(cartesianTransform(lastMouseX, 'x'))
+ ", "
+ floor(cartesianTransform(lastMouseY, 'y')),
0 + screenScale.val*10,
height - screenScale.val*10);
break;
};
};
};