/* The puzzling fancy triangle. Why did it work with fanciness = 5, but not with fanciness = 6 ? I wish I had thought of this and done it on purpose. Before ever getting to a good solid draw_distance function, draw_fancier has been called 6 times, each time dividing the distance by three. They are integer divisions, so after a while the distance being drawn was always zero. This is the original version with the mistake in it, a corrected version (using doubles) is below. #include "library.h" void draw_fancier(const int dist, const int fanciness) { if (fanciness == 0) draw_distance(dist); else { draw_fancier(dist/3, fanciness - 1); turn_left_by_degrees(60); draw_fancier(dist/3, fanciness - 1); turn_right_by_degrees(120); draw_fancier(dist/3, fanciness - 1); turn_left_by_degrees(60); draw_fancier(dist/3, fanciness - 1); } } void draw_triangle(const int side, const int fanciness) { draw_fancier(side, fanciness); turn_right_by_degrees(120); draw_fancier(side, fanciness); turn_right_by_degrees(120); draw_fancier(side, fanciness); turn_right_by_degrees(120); } void main() { make_window(600, 600); set_pen_color(color::black); move_to(300, 150); set_heading_degrees(120); draw_triangle(300, 6); } */ #include "library.h" void draw_fancier(const double dist, const int fanciness) { if (fanciness == 0) draw_distance(dist); else { draw_fancier(dist/3, fanciness - 1); turn_left_by_degrees(60); draw_fancier(dist/3, fanciness - 1); turn_right_by_degrees(120); draw_fancier(dist/3, fanciness - 1); turn_left_by_degrees(60); draw_fancier(dist/3, fanciness - 1); } } void draw_triangle(const double side, const int fanciness) { draw_fancier(side, fanciness); turn_right_by_degrees(120); draw_fancier(side, fanciness); turn_right_by_degrees(120); draw_fancier(side, fanciness); turn_right_by_degrees(120); } void main() { make_window(600, 600); set_pen_color(color::black); move_to(300, 50); set_heading_degrees(150); draw_triangle(400, 6); }