#include "library.h" const double pi = acos(-1.0), ang = atan(6.0), beta = pi/2 - ang, mul = sqrt(1 + 1.0/36); double draw_dist(double len, double min) { if (len < min) { draw_distance(len); return len; } const double d1 = draw_dist(len/3, min); turn_left_by_radians(ang); const double d2 = draw_dist(mul * len/3, min); turn_right_by_radians(pi - 2 * beta); const double d3 = draw_dist(mul *len/3, min); turn_left_by_radians(ang); const double d4 = draw_dist(len/3, min); return d1 + d2 + d3 + d4; } double draw_triangle(double side, double min) { const double d1 = draw_dist(side, min); turn_right_by_degrees(120); const double d2 = draw_dist(side, min); turn_right_by_degrees(120); const double d3 = draw_dist(side, min); turn_right_by_degrees(120); return d1 + d2 + d3; } void main() { print("Minimum lines size? "); const double min = read_double(); make_window(600, 600); move_to(100, 420); set_heading_degrees(30); const double p = draw_triangle(400, min); print("perimeter = "); print(p); new_line(); }