build: вариант 2
Этот коммит содержится в:
@@ -1,5 +1,5 @@
|
||||
# depslib dependency file v1.0
|
||||
1682333921 source:c:\users\hp\desktop\lab-03\project3\main.cpp
|
||||
1685882979 source:c:\users\hp\desktop\lab-03\project3\main.cpp
|
||||
<iostream>
|
||||
<vector>
|
||||
<cmath>
|
||||
@@ -12,7 +12,7 @@
|
||||
1682271918 c:\users\hp\desktop\lab-03\project3\histogram.h
|
||||
<vector>
|
||||
|
||||
1682280773 source:c:\users\hp\desktop\lab-03\project3\histogram.cpp
|
||||
1685882979 source:c:\users\hp\desktop\lab-03\project3\histogram.cpp
|
||||
<iostream>
|
||||
<vector>
|
||||
<cmath>
|
||||
@@ -20,7 +20,7 @@
|
||||
"histogram_internal.h"
|
||||
<conio.h>
|
||||
|
||||
1682280773 source:c:\users\hp\desktop\lab-03\project3\text.cpp
|
||||
1685882979 source:c:\users\hp\desktop\lab-03\project3\text.cpp
|
||||
<iostream>
|
||||
<vector>
|
||||
<cmath>
|
||||
@@ -33,14 +33,12 @@
|
||||
1682275464 c:\users\hp\desktop\lab-03\project3\histogram_internal.h
|
||||
<vector>
|
||||
|
||||
1682282112 source:c:\users\hp\desktop\lab-03\project3\svg.cpp
|
||||
<math.h>
|
||||
1685883368 source:c:\users\hp\desktop\lab-03\project3\svg.cpp
|
||||
<iostream>
|
||||
<conio.h>
|
||||
<vector>
|
||||
<string>
|
||||
"svg.h"
|
||||
<math.h>
|
||||
<string>
|
||||
|
||||
1682278136 c:\users\hp\desktop\lab-03\project3\svg.h
|
||||
1685882979 c:\users\hp\desktop\lab-03\project3\svg.h
|
||||
<vector>
|
||||
|
||||
|
||||
@@ -2,42 +2,32 @@
|
||||
<CodeBlocks_layout_file>
|
||||
<FileVersion major="1" minor="0" />
|
||||
<ActiveTarget name="Debug" />
|
||||
<File name="svg.cpp" open="1" top="1" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<File name="histogram_internal.h" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="819" topLine="14" />
|
||||
<Cursor1 position="171" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="histogram.cpp" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<File name="text.h" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="133" topLine="0" />
|
||||
<Cursor1 position="171" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="histogram_internal.h" open="1" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="0" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="main.cpp" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="677" topLine="23" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="text.cpp" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<File name="text.cpp" open="1" top="1" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="95" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="svg.h" open="1" top="0" tabpos="9" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<File name="main.cpp" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="98" topLine="0" />
|
||||
<Cursor1 position="127" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="text.h" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<File name="histogram.cpp" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="0" topLine="0" />
|
||||
<Cursor1 position="367" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="histogram.h" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<File name="histogram.h" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="175" topLine="0" />
|
||||
</Cursor>
|
||||
|
||||
33
svg.cpp
33
svg.cpp
@@ -1,11 +1,9 @@
|
||||
#include <math.h>
|
||||
#include <iostream>
|
||||
#include <conio.h>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "svg.h"
|
||||
using namespace std;
|
||||
#include <math.h>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
void
|
||||
svg_begin(double width, double height) {
|
||||
@@ -21,17 +19,22 @@ void
|
||||
svg_end() {
|
||||
cout << "</svg>\n";
|
||||
}
|
||||
|
||||
int color(int bin, int max_count) {
|
||||
int color;
|
||||
return color = round((10 - (bin * 9) / max_count));
|
||||
}
|
||||
|
||||
void
|
||||
svg_text(double left, double baseline, string text) {
|
||||
cout << "<text x='" << left << "' y='" << baseline << "'>" << text << "</text>";
|
||||
cout << "<text x='" << left << "' y='" << baseline << "' > " << text << "</text>";
|
||||
}
|
||||
|
||||
void svg_rect(double x, double y, double width, double height, string colour = "black", string fill = "black"){
|
||||
cout << "<rect x='"<<x<<"' y='"<<y<<"' width='"<<width<<"' height='"<<height<<"' stroke = '"<<colour <<"' fill = '"<<fill<<"' />";
|
||||
void svg_rect(double x, double y, double width, double height, string stroke, string fill) {
|
||||
cout << "<rect x='" << x << "' y='" << y << "' width='" << width << "' height='" << height << "' stroke='" << "#" << stroke << stroke << stroke << "' fill='" << "#" << fill << fill << fill << "'>" << "</rect>";
|
||||
}
|
||||
|
||||
void
|
||||
show_histogram_svg(const vector<size_t>& bins) {
|
||||
void show_histogram_svg(const vector<size_t>& bins) {
|
||||
const auto IMAGE_WIDTH = 400;
|
||||
const auto IMAGE_HEIGHT = 300;
|
||||
const auto TEXT_LEFT = 20;
|
||||
@@ -39,17 +42,21 @@ show_histogram_svg(const vector<size_t>& bins) {
|
||||
const auto TEXT_WIDTH = 50;
|
||||
const auto BIN_HEIGHT = 30;
|
||||
const auto BLOCK_WIDTH = 10;
|
||||
|
||||
|
||||
svg_begin(400, 300);
|
||||
|
||||
double top = 0;
|
||||
double max_count = bins[0];
|
||||
for (size_t i = 0; i < bins.size(); i++) {
|
||||
if (bins[i] > max_count)
|
||||
max_count = bins[i];
|
||||
}
|
||||
svg_begin(400, 300);
|
||||
for (size_t bin : bins) {
|
||||
const double bin_width = (IMAGE_WIDTH - TEXT_WIDTH)*(bin/max_count);
|
||||
int temp_color = color(bin, max_count);
|
||||
const double bin_width = (IMAGE_WIDTH - TEXT_WIDTH) * (bin / max_count);
|
||||
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin));
|
||||
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "blue", "#FF00FF");
|
||||
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, to_string(temp_color), to_string(temp_color));
|
||||
top += BIN_HEIGHT;
|
||||
}
|
||||
svg_end();
|
||||
|
||||
Ссылка в новой задаче
Block a user