Skip to content

Commit

Permalink
[CPP] Logo turtle position as double intead of int
Browse files Browse the repository at this point in the history
  • Loading branch information
scopeInfinity committed Sep 27, 2021
1 parent a9a3a15 commit 7a929ee
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions src/usr/local/src/logo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ std::vector<std::string> split(std::string &str) {

class Display {
int height;
typedef std::pair<int,int> Point; // x, y
typedef std::pair<double, double> Point; // x, y
#define _x first
#define _y second
std::vector<std::pair<Point, Point> > lines;
Expand Down Expand Up @@ -76,8 +76,8 @@ class Display {

void action_forward(int len) {
Point next = current;
next._x += std::round(len*std::cos(angle));
next._y -= std::round(len*std::sin(angle)); // graphics and maths y coordinates are flipped
next._x += len*std::cos(angle);
next._y -= len*std::sin(angle); // graphics and maths y coordinates are flipped
action_move(next);
}

Expand Down Expand Up @@ -236,8 +236,10 @@ class Display {
std::graphics::setcolor(BLACK);

for(const auto &line: lines) {
std::graphics::line(line.first.first, line.first.second,
line.second.first, line.second.second);
std::graphics::line(std::round(line.first.first),
std::round(line.first.second),
std::round(line.second.first),
std::round(line.second.second));
}

if (turtle_visiblity) {
Expand All @@ -250,10 +252,26 @@ class Display {
Point e2 = at_distance(current, turtle_len, angle + M_PI*7/6);
Point eb = at_distance(current, turtle_len/2, angle + M_PI);

std::graphics::line(e1._x, e1._y, current._x, current._y);
std::graphics::line(e1._x, e1._y, eb._x, eb._y);
std::graphics::line(e2._x, e2._y, current._x, current._y);
std::graphics::line(e2._x, e2._y, eb._x, eb._y);
std::graphics::line(
std::round(e1._x),
std::round(e1._y),
std::round(current._x),
std::round(current._y));
std::graphics::line(
std::round(e1._x),
std::round(e1._y),
std::round(eb._x),
std::round(eb._y));
std::graphics::line(
std::round(e2._x),
std::round(e2._y),
std::round(current._x),
std::round(current._y));
std::graphics::line(
std::round(e2._x),
std::round(e2._y),
std::round(eb._x),
std::round(eb._y));
}

std::graphics::graphflush();
Expand Down Expand Up @@ -341,7 +359,7 @@ class Console {
}
const int char_per_line = (WINDOW_WIDTH-2*border)/text_width;
for (std::size_t i = 0; i < line_count; i++) {
int _y = y_offset+(i+1)*text_height;
int _y = y_offset+(i+1)*text_height ;
int _x = border;
int str_start = char_per_line*i;
int str_end = char_per_line*(i+1); // excluding
Expand Down

0 comments on commit 7a929ee

Please sign in to comment.