#include "library.h" // version 1: we say through a parameter how fancy the line // is supposed to be. When the fanciness is zero, a simple // straight line is drawn. void draw_line1(double len, int fanciness) { if (fanciness == 0) draw_distance(len); else { draw_line1(len/3, fanciness-1); turn_left_by_degrees(80); draw_line1(len/3*1.3, fanciness-1); turn_right_by_degrees(160); draw_line1(len/3*1.3, fanciness-1); turn_left_by_degrees(80); draw_line1(len/3, fanciness-1); } } // version 2: this automatically gets as fancy as the display // resolution can handle. Once the distance to be covered is // significantly less that one pixel, no detail is going to // be visible. void draw_line2(double len) { if (len < 0.5) draw_distance(len); else { draw_line2(len/3); turn_left_by_degrees(60); draw_line2(len/3); turn_right_by_degrees(120); draw_line2(len/3); turn_left_by_degrees(60); draw_line2(len/3); } } void draw_tri(double len, int f) { draw_line1(len, f); turn_right_by_degrees(120); draw_line1(len, f); turn_right_by_degrees(120); draw_line1(len, f); turn_right_by_degrees(120); void test() { const int f = read_int(); set_pen_color(color::white); fill_rectangle(0, 0, 600, 600); set_pen_color(color::red); move_to(100, 420); set_heading_degrees(30); draw_tri(400.0, f); new_line(); test(); } void main() { make_window(600, 600); set_pen_width(1); test(); }