-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathartwork.c
More file actions
86 lines (56 loc) · 1.69 KB
/
artwork.c
File metadata and controls
86 lines (56 loc) · 1.69 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
#include "artwork.h"
#include <math.h>
void draw_line(Motor* motorX, Motor* motorY, Point* point, Stylus* stylus) {
double deltaX = 0;
double deltaY = 0;
double angle = 0;
double numStepsX = 0;
double numStepsY = 0;
int stepsTakenX = 0;
int stepsTakenY = 0;
if (point->x != stylus->currentX || point->y != stylus->currentY) {
current_steps_x = floor(stylus->currentX / LINEAR_STEP);
current_steps_y = floor(stylus->currentY / LINEAR_STEP);
next_point_steps_x = floor(point->x / LINEAR_STEP)
next_point_steps_y = floor(point->y / LINEAR_STEP)
deltaX = current_steps_x - next_point_steps_x;
deltaY = current_steps_y - next_point_steps_y;
// adjust for negative direction
if deltaX < 0:
deltaX = -deltaX;
x_dir = 1 // anticlockwise
else:
x_dir = 0 // clockwise
if deltaY < 0:
deltaY = -deltaY;
y_dir = 1 // anticlockwise
else:
y_dir = 0 // clockwise
gcd =
angle = atan(deltaY / deltaX);
numStepsX = floor(deltaX / LINEAR_STEP);
numStepsY = floor(deltaY / LINEAR_STEP);
printw("Ratio: %lf\n", 2 * angle / M_PI);
printw("Pi: %lf\n", M_PI);
}
}
void sketch_artwork(Artwork* artwork, Motor* motorX, Motor* motorY,
Stylus* stylus, Servo* servo) {
Segment* segment;
Point* point;
stylus->currentX = 0;
stylus->currentY = 0;
printw("Stylus: (%f, %f)\n", stylus->currentX, stylus->currentY);
int numPoints;
int segments = artwork->numSegments;
for (int i = 0; i < segments; ++i) {
segment = artwork->segments[i];
numPoints = segment->numPoints;
for (int j = 0; j < numPoints; ++j) {
// Calculate ratios of the lines
point = segment->points[j];
draw_line(motorX, motorY, point, stylus);
}
printw("\n");
}
}