67 lines
1.8 KiB
C++

//
// Created by Nik on 11/04/2022.
//
#include "Diamand.h"
Diamand::Diamand(ColorCode color, unsigned int redius): Shape2D(color), redius(redius) {}
unsigned int Diamand::getSurfaceArea() const {
return (redius*2+2)*2;
}
void Diamand::draw() const {
int spacL1 = redius;
int specR1 = 0;
int spacL2 = 0;
int specR2 = redius * 2;
for (int i = 0; i < redius * 2 + 2; i++) {
if (i <= redius) {
for (int j = 0; j < spacL1; j++) std::cout << " ";
PrintUtility::print(color, "*");
for (int k = 0; k < specR1; k++) std::cout << " ";
PrintUtility::print(color, "*");
std::cout << "\n";
specR1 += 2;
spacL1 -= 1;
}
if (i > redius) {
for (int j = 0; j < spacL2; j++) std::cout << " ";
PrintUtility::print(color, "*");
for (int k = 0; k < specR2; k++) std::cout << " ";
PrintUtility::print(color, "*");
std::cout << "\n";
specR2 -= 2;
spacL2 += 1;
}
}
}
std::string Diamand::getString() const {
std::string ret;
int spacL1 = redius;
int specR1 = 0;
int spacL2 = 0;
int specR2 = redius * 2;
for (int i = 0; i < redius * 2 + 2; i++) {
if (i <= redius) {
for (int j = 0; j < spacL1; j++) ret+=" ";
ret+="*";
for (int k = 0; k < specR1; k++) ret+=" ";
ret+="*\n";
specR1 += 2;
spacL1 -= 1;
}
if (i > redius) {
for (int j = 0; j < spacL2; j++) ret+=" ";
ret+="*";
for (int k = 0; k < specR2; k++) ret+=" ";
ret+="*\n";
specR2 -= 2;
spacL2 += 1;
}
}
return ret;
}