-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathembroidery.cpp
136 lines (131 loc) · 3.89 KB
/
embroidery.cpp
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
129
130
131
132
133
134
135
136
#include <cs70/turtle.hpp>
#include <iostream>
#include <fstream>
#include <string>
#include <cstddef>
#include "embroidery.hpp"
using namespace std;
void rect(Turtle& t, float width, float height) {
t.pendown();
t.move(width, 0);
t.move(0, height);
t.move(-1*width, 0);
t.move(0, -1*height);
}
void meetTurtle() {
const float PATCH_WIDTH = 50;
const float PATCH_HEIGHT = 40;
const int EDGE_STITCH_SIZE = 2;
const int TEXT_STITCH_SIZE = 1;
const float FONT_SIZE = 1.0;
const float SATIN_DELTA = 0.3;
Turtle t;
t.satinon(SATIN_DELTA);
t.setStepSize(EDGE_STITCH_SIZE);
rect(t, PATCH_WIDTH, PATCH_HEIGHT);
t.setStepSize(TEXT_STITCH_SIZE);
t.penup();
t.gotopoint(PATCH_WIDTH/3, PATCH_HEIGHT/4);
t.pendown();
t.displayMessage("LO", FONT_SIZE);
t.penup();
t.gotopoint(PATCH_WIDTH/3, PATCH_HEIGHT/2);
t.pendown();
t.displayMessage("Bluh", FONT_SIZE);
t.penup();
t.gotopoint(PATCH_WIDTH/3, 3*PATCH_HEIGHT/4);
t.pendown();
t.displayMessage("IH", FONT_SIZE);
t.end();
t.save("meet_turtle.dst");
}
void plotExampleData() {
const float PATCH_WIDTH = 50;
const float PATCH_HEIGHT = 40;
const int EDGE_STITCH_SIZE = 2;
const float FONT_SIZE = 1.0;
const float SATIN_DELTA = 0.3;
const int PLOT_STITCH_SIZE = 1;
const int NUM_DATA_POINTS = 59;
const string INPUT_NAME = "/home/student/data/hw2/us_population_growth.txt";
const string OUTPUT_NAME = "example_data.dst";
ifstream inputFile;
inputFile.open(INPUT_NAME);
float data[NUM_DATA_POINTS];
for (int i = 0; i < NUM_DATA_POINTS; i++) {
inputFile >> data[i];
}
inputFile.close();
float max = 0;
for (int i = 0; i < NUM_DATA_POINTS; i++) {
if (data[i] > max) {
max = data[i];
}
}
float availableHeight = PATCH_HEIGHT - EDGE_STITCH_SIZE;
float normalized[NUM_DATA_POINTS];
for (int i = 0; i < NUM_DATA_POINTS; i++) {
normalized[i] = data[i] * availableHeight/max;
}
Turtle t;
t.satinon(SATIN_DELTA);
t.setStepSize(EDGE_STITCH_SIZE);
rect(t, PATCH_WIDTH, PATCH_HEIGHT);
t.setStepSize(PLOT_STITCH_SIZE);
t.pendown();
float x = (PATCH_WIDTH - EDGE_STITCH_SIZE)/NUM_DATA_POINTS;
for (int i = 0; i < NUM_DATA_POINTS; i++) {
t.gotopoint(x*(i+1), normalized[i]);
}
t.penup();
t.gotopoint(PATCH_WIDTH/3, PATCH_HEIGHT-4*EDGE_STITCH_SIZE);
t.pendown();
t.displayMessage("1992", FONT_SIZE);
t.end();
t.save(OUTPUT_NAME);
}
void plotStudentData() {
const float PATCH_WIDTH = 50;
const float PATCH_HEIGHT = 40;
const int EDGE_STITCH_SIZE = 2;
const float FONT_SIZE = 1.0;
const float SATIN_DELTA = 0.3;
const int PLOT_STITCH_SIZE = 1;
const int NUM_DATA_POINTS = 50;
const string INPUT_NAME = "student_data.txt";
const string OUTPUT_NAME = "student_data.dst";
ifstream inputFile;
inputFile.open(INPUT_NAME);
float data[NUM_DATA_POINTS];
for (int i = 0; i < NUM_DATA_POINTS; i++) {
inputFile >> data[i];
}
inputFile.close();
float max = 0;
for (int i = 0; i < NUM_DATA_POINTS; i++) {
if (data[i] > max) {
max = data[i];
}
}
float availableHeight = PATCH_HEIGHT - EDGE_STITCH_SIZE;
float normalized[NUM_DATA_POINTS];
for (int i = 0; i < NUM_DATA_POINTS; i++) {
normalized[i] = data[i] * availableHeight/max;
}
Turtle t;
t.satinon(SATIN_DELTA);
t.setStepSize(EDGE_STITCH_SIZE);
rect(t, PATCH_WIDTH, PATCH_HEIGHT);
t.setStepSize(PLOT_STITCH_SIZE);
t.pendown();
float x = (PATCH_WIDTH - EDGE_STITCH_SIZE)/NUM_DATA_POINTS;
for (int i = 0; i < NUM_DATA_POINTS; i++) {
t.gotopoint(x*(i+1), normalized[i]);
}
t.penup();
t.gotopoint(PATCH_WIDTH/3, PATCH_HEIGHT/2);
t.pendown();
t.displayMessage("TEMP", FONT_SIZE);
t.end();
t.save(OUTPUT_NAME);
}