条件、循环、函数定义 练习
2017-09-13 16:13 082何晓琳 阅读(201) 评论(0) 编辑 收藏 举报1.画五角星
import turtle turtle.color('red') turtle.fillcolor('blue') turtle.begin_fill() for i in range(5): turtle.forward(100) turtle.right(144) turtle.end_fill()
2.画同心圆
import turtle for i in range(5): turtle.up() turtle.goto(0,-20*(i+1)) turtle.down() turtle.circle(20*(i+1))
3.画太阳花
import turtle turtle.color('black') turtle.fillcolor('pink') turtle.begin_fill() while True: turtle.forward(200) turtle.left(170) if(abs(turtle.pos()))<1: break
4.画五个五角星
import turtle turtle.color('yellow') turtle.fillcolor('yellow') turtle.bgcolor('red') def my_goto(x,y): turtle.up() turtle.goto(x,y) turtle.down() def my_draw5(r): turtle.begin_fill() for i in range(5): turtle.forward(r) turtle.right(144) turtle.end_fill() my_goto(-700,250) my_draw5(100) my_goto(-520,350) my_draw5(30) my_goto(-450,280) my_draw5(30) my_goto(-450,200) my_draw5(30) my_goto(-520,120) my_draw5(30)
5.画◇花瓣的太阳花。
import turtle def draw_diamond(brad): brad.forward(100) brad.right(45) brad.forward(100) brad.right(135) def draw_art(): window=turtle.Screen() window.bgcolor('black') brad=turtle.Turtle() brad.shape('turtle') brad.color('yellow') brad.speed('fastest') for i in range(1,37): draw_diamond(brad) draw_diamond(brad) brad.left(10) brad.right(90) brad.forward(300) brad.hideturtle() window.exitionclick() draw_art()