-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathMisc.pde
109 lines (92 loc) · 3.73 KB
/
Misc.pde
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
///////////////////////////////////////////////////////////////////////////////////////////////////////
// A class to check the upper and lower limits of a value
class Limit {
float min = 2147483647;
float max = -2147483648;
Limit() { }
void update_limit(float value_) {
if (value_ < min) { min = value_; }
if (value_ > max) { max = value_; }
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////
void grid() {
// This will give you a rough idea of the size of the printed image, in "grid_scale" units.
// Some screen scales smaller than 1.0 will sometimes display every other line
// It looks like a big logic bug, but it just can't display a one pixel line scaled down well.
blendMode(BLEND);
if (is_grid_on) {
int image_center_x = int(img.width / 2);
int image_center_y = int(img.height / 2);
int gridlines = 100;
// Give everything outside the paper area a light grey color
noStroke();
fill(0, 0, 0, 32);
float border_x = (paper_size_x - image_size_x) / 2;
float border_y = (paper_size_y - image_size_y) / 2;
rect(-border_x/gcode_scale, -border_y/gcode_scale, 999999, -999999);
rect((image_size_x+border_x)/gcode_scale, -border_y/gcode_scale, 999999, 999999);
rect((image_size_x+border_x)/gcode_scale, (image_size_y+border_y)/gcode_scale, -999999, 999999);
rect(-border_x/gcode_scale, (image_size_y+border_y)/gcode_scale, -999999, -999999);
// Vertical lines
strokeWeight(1);
stroke(255, 64, 64, 80);
noFill();
for (int x = -gridlines; x <= gridlines; x++) {
int x0 = int(x * grid_scale / gcode_scale);
line(x0 + image_center_x, -999999, x0 + image_center_x, 999999);
}
// Horizontal lines
for (int y = -gridlines; y <= gridlines; y++) {
int y0 = int(y * grid_scale / gcode_scale);
line(-999999, y0 + image_center_y, 999999, y0 + image_center_y);
}
// Screen center line
stroke(255, 64, 64, 80);
strokeWeight(4);
line(image_center_x, -999999, image_center_x, 999999);
line(-999999, image_center_y, 999999, image_center_y);
strokeWeight(1);
hint(DISABLE_DEPTH_TEST); // Allow fills to be shown on top.
// Mark the edge of the drawing/image area in blue
stroke(64, 64, 255, 92);
noFill();
strokeWeight(2);
rect(0, 0, img.width, img.height);
// Green pen origin (home position) dot.
stroke(0, 255, 0, 255);
fill(0, 255, 0, 255);
ellipse(-gcode_offset_x / gcode_scale, -gcode_offset_y / gcode_scale, 10, 10);
// Red center of image dot
stroke(255, 0, 0, 255);
fill(255, 0, 0, 255);
ellipse(image_center_x, image_center_y, 10, 10);
// Blue dot at image 0,0
stroke(0, 0, 255, 255);
fill(0, 0, 255, 255);
ellipse(0, 0, 10, 10);
hint(ENABLE_DEPTH_TEST);
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////
// Experimental, mark coordinates of mouse locations to console.
// Useful for locating vanishing points etc.
// Currently works correctly with screen_scale, translation and rotation.
void mouse_point() {
print("Mouse point: ");
switch(screen_rotate) {
case 0:
println( (mouseX/screen_scale - mx) + ", " + (mouseY/screen_scale - my) );
break;
case 1:
println( (mouseY/screen_scale - my) + ", " + -(mouseX/screen_scale - mx) );
break;
case 2:
println( -(mouseX/screen_scale - mx) + ", " + -(mouseY/screen_scale - my) );
break;
case 3:
println( -(mouseY/screen_scale - my) + ", " + (mouseX/screen_scale - mx) );
break;
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////