From 538508ef981039629ca55f920e89c62f31dc12c7 Mon Sep 17 00:00:00 2001
From: SukhotinMD <SukhotinMD@mpei.ru>
Date: Thu, 29 May 2025 07:37:13 +0300
Subject: [PATCH] code: work done

---
 ARM64/Debug/marks.svg |   8 +++-
 ProgUit Lab1/text.cpp | 107 +++++++++++++++---------------------------
 2 files changed, 45 insertions(+), 70 deletions(-)

diff --git a/ARM64/Debug/marks.svg b/ARM64/Debug/marks.svg
index d894513..fd119d4 100644
--- a/ARM64/Debug/marks.svg
+++ b/ARM64/Debug/marks.svg
@@ -1,5 +1,9 @@
 <?xml version='1.0' encoding='UTF-8'?>
 <svg width='400' height='300' viewBox='0 0 400 300' xmlns='http://www.w3.org/2000/svg'>
-<text x='20' y='35'>2</text>
-<rect x='50' y='0' width='20' height='30' stroke = 'purple' fill='red' />
+<text x='20' y='20'>2</text>
+<rect x='50' y='0' width='140' height='30' stroke='grey' fill='#319c28' />
+<text x='20' y='50'>5</text>
+<rect x='50' y='30' width='350' height='30' stroke='grey' fill='#7d79c6' />
+<text x='20' y='80'>3</text>
+<rect x='50' y='60' width='210' height='30' stroke='grey' fill='#5e7341' />
 </svg>
diff --git a/ProgUit Lab1/text.cpp b/ProgUit Lab1/text.cpp
index 9413993..3aeb1ec 100644
--- a/ProgUit Lab1/text.cpp	
+++ b/ProgUit Lab1/text.cpp	
@@ -1,6 +1,9 @@
 #include <iostream>
 #include <vector>
 #include <string>
+#include <random>
+#include <sstream>
+#include <iomanip>
 
 #include "text.h"
 #include "histogram.h"
@@ -9,6 +12,25 @@
 
 using namespace std;
 
+std::string getRandomHexColor() {
+	random_device rd;  // �������� ��������� �����
+	mt19937 gen(rd()); // ��������� Mersenne Twister
+	std::uniform_int_distribution<> dis(0, 255); // ����������� ������������� [0, 255]
+
+	int r = dis(gen); // �������
+	int g = dis(gen); // �������
+	int b = dis(gen); // �����
+
+	// ��������� HEX-������
+	std::stringstream hexStream;
+	hexStream << "#"
+		<< std::hex << std::setw(2) << std::setfill('0') << r
+		<< std::hex << std::setw(2) << std::setfill('0') << g
+		<< std::hex << std::setw(2) << std::setfill('0') << b;
+
+	return hexStream.str();
+}
+
 void
 svg_begin(double width, double height) {
 	cout << "<?xml version='1.0' encoding='UTF-8'?>\n";
@@ -29,97 +51,46 @@ svg_text(double left, double baseline, string text) {
 	cout << "<text x='" << left << "' y='" << baseline << "'>" << text << "</text>" << endl;
 }
 
-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 << "' fill='" << fill << "' />" << endl;
+void svg_rect(double x, double y, double width, double height, string stroke = "black", string fill = "black") {
+	cout << "<rect x='" << x << "' y='" << y << "' width='" << width << "' height='" << height << "' stroke='" << stroke << "' fill='" << fill << "' />" << endl;
 }
 
 void
 show_histogram_svg(const vector<size_t> bins) {
 
+	auto mm = *(max_element(bins.begin(), bins.end()));
 	const auto IMAGE_WIDTH = 400;
 	const auto IMAGE_HEIGHT = 300;
 	const auto TEXT_LEFT = 20;
 	const auto TEXT_BASELINE = 20;
 	const auto TEXT_WIDTH = 50;
 	const auto BIN_HEIGHT = 30;
-	const auto BLOCK_WIDTH = 10;
-
-	
+	auto BLOCK_WIDTH = 10;
 
+	BLOCK_WIDTH = (IMAGE_WIDTH - TEXT_WIDTH) / mm;
 
 	svg_begin(400, 300);
-	svg_text(20, 35, to_string(bins[0]));
-	svg_rect(50, 0, bins[0] * 10, 30, "purple", "red");
-	svg_end();
-
-}
-
-
-
-
-
-void show_histogram_text(const vector <size_t> bins, const size_t bin_count) {
-	// ������������ � ���������
-
-
-	const size_t SCREEN_WIDTH = 80;
-	const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
-
-	int max_in_bins = 0;
-
-
-	for (int i = 0; i < bin_count; i++) {
-		if (bins[i] > max_in_bins) {
-			max_in_bins = bins[i];
-		}
-	}
-
-
-	if (max_in_bins > MAX_ASTERISK) {
-
-		for (int i = 0; i < bin_count; i++) {
-			if (bins[i] < 100) {
-				cout << " ";
-			}
-			if (bins[i] < 10) {
-				cout << " ";
-			}
-			size_t height = MAX_ASTERISK * (static_cast<double>(bins[i]) / max_in_bins);
-
-			cout << bins[i] << "|";
 
+	
 
-			for (int j = 0; j < height; j++) {
-				cout << "*";
-			}
-			cout << endl;
-		}
+	double top = 0;
+	for (size_t bin : bins) {
+		const double bin_width = BLOCK_WIDTH * bin;
 
+		svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin));
 
+		svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "grey", getRandomHexColor());
+		top += BIN_HEIGHT;
 	}
-	else {
-		// ���� ������������ ����� ����� ������� ������ ��� ����� 76
-		for (int i = 0; i < bin_count; i++) {
-			if (bins[i] < 100) {
-				cout << " ";
-			}
-			if (bins[i] < 10) {
-				cout << " ";
-			}
 
 
-			cout << bins[i] << "|";
-			for (int j = 0; j < bins[i]; j++) {
-				cout << "*";
-			}
-			cout << endl;
-		}
-
-
-	}
 
+	//svg_begin(400, 300);
+	//svg_text(20, 35, to_string(bins[0]));
+	//svg_rect(50, 0, bins[0] * 10, 30, "purple", "red");
+	svg_end();
 
+}
 
 
 
-}
\ No newline at end of file