直接上题和代码
5.53 (Turtle:绘制sin和cos函数)编写程序绘制蓝色的sin函数和红色的cos函数。
代码和结果
turtle. speed( 10 )
turtle. penup( )
turtle. color( "blue" )
turtle. goto( - 175 , 50 * math. sin( ( - 175 / 100 * 2 * math. pi) ) )
turtle. pendown( )
for x in range ( - 175 , 176 ) : turtle. goto( x, 50 * math. sin( ( x / 100 * 2 * math. pi) ) ) turtle. penup( )
turtle. color( "red" )
turtle. goto( - 175 , 50 * math. cos( ( - 175 / 100 * 2 * math. pi) ) )
turtle. pendown( )
for x in range ( - 175 , 176 ) : turtle. goto( x, 50 * math. cos( ( x / 100 * 2 * math. pi) ) ) turtle. penup( )
turtle. color( "black" )
turtle. goto( - 300 , 0 )
turtle. pendown( )
turtle. goto( 300 , 0 )
turtle. penup( )
turtle. goto( 0 , 300 )
turtle. pendown( )
turtle. goto( 0 , - 300 )
turtle. penup( )
turtle. goto( - 100 , - 15 )
turtle. write( "-2\u03c0" )
turtle. goto( 100 , - 15 )
turtle. write( "2\u03c0" )
turtle. hideturtle( )
turtle. done( )
晚上继续练习阿斯汤伽