From 31b39974c841b0a041f901a6ddd148bb22ab1c16 Mon Sep 17 00:00:00 2001 From: SavinSA Date: Mon, 22 Apr 2024 13:50:03 +0300 Subject: [PATCH] =?UTF-8?q?svg:=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=20=D0=B2=D0=B2=D0=BE=D0=B4=20=D1=86=D0=B2=D0=B5?= =?UTF-8?q?=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.cpp | 6 +++++- svg.cpp | 10 +++++----- svg.h | 3 ++- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/main.cpp b/main.cpp index df865ea..7eebd7d 100644 --- a/main.cpp +++ b/main.cpp @@ -8,6 +8,7 @@ using namespace std; struct Input { vector numbers; size_t bin_count{}; + string stroke; }; Input @@ -26,6 +27,9 @@ input_data() { cerr << "Enter bin count: "; cin >> in.bin_count; + + cerr << "Enter stroke colour:"; + cin >> in.stroke; return in; } @@ -35,6 +39,6 @@ int main() const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1; auto in = input_data(); auto bins = make_histogram(in.numbers, in.bin_count); - show_histogram_svg(bins); + show_histogram_svg(bins, in.stroke); return 0; } diff --git a/svg.cpp b/svg.cpp index fa125ef..83b98c0 100644 --- a/svg.cpp +++ b/svg.cpp @@ -1,8 +1,8 @@ #include #include #include +#include "svg.h" using namespace std; - void svg_begin(double width, double height) { cout << "\n"; @@ -24,14 +24,14 @@ svg_text(double left, double baseline, string text) { } void -svg_rect(double x, double y, double width, double height, string stroke, string fill) { +svg_rect(double x, double y, double width, double height, string& stroke, string fill) { cout << ""; } void -show_histogram_svg(const vector& bins) { +show_histogram_svg(const vector& bins, string stroke) { const auto IMAGE_WIDTH = 400; const auto IMAGE_HEIGHT = 300; const auto TEXT_LEFT = 20; @@ -47,13 +47,13 @@ show_histogram_svg(const vector& bins) { max_count = (bin * BLOCK_WIDTH); } } - + svg_begin(400, 300); double top = 0; for (double bin : bins) { const double bin_width = MAX_WIDTH * ((BLOCK_WIDTH * bin) / max_count); svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin)); - svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "green", "yellow"); + svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, stroke, "red"); top += BIN_HEIGHT; } svg_end(); diff --git a/svg.h b/svg.h index f29e7e3..dc3ea4a 100644 --- a/svg.h +++ b/svg.h @@ -1,3 +1,4 @@ #pragma once #include -void show_histogram_svg(const std::vector& bins); +#include +void show_histogram_svg(const std::vector& bins, std::string stroke);