Python海龟绘画制图的相关代码
#导入工具 # import turtle #定义一个画布尺寸的两种方式 turtle.screensize(100,100) turtle.setup(800,600,700,200) #定义画笔 turtle.shape('turtle') #定义画笔颜色 turtle.pencolor('blue') #定义画笔大小 turtle.pensize(10) #定义绘画速度 turtle.speed(0) #定义画笔向前走的距离 turtle.forward(200) #定义画笔位置 turtle.goto(100,100) #画笔右转90° turtle.right(90) #画笔左转180° turtle.left(180) #画笔旋转,默认顺时针旋转 turtle.setheading(-180) #画笔的绝对坐标位置 turtle.goto(100,50) #向后走 turtle.backward(200) #颜色模式改为RGB turtle.colormode(255) #结束海龟 turtle.done() #点击画布外面,关闭窗口 turtle.exitonclick() turtle.screensize(500,500) turtle.shape('turtle') turtle.pencolor('red') turtle.pensize(10) turtle.forward(200) turtle.left(90) turtle.forward(200) turtle.left(90) turtle.forward(200) turtle.left(90) turtle.forward(200) turtle.done() turtle.screensize(800,800) turtle.pencolor('black') turtle.pensize(1) turtle.circle(100) turtle.left(90) turtle.circle(100,360) turtle.right(180) turtle.circle(100,360) turtle.circle(100,steps=5) #抬笔 turtle.penup() turtle.goto(100,100) #落笔 turtle.pendown() #一个点 turtle.dot(10,'green') turtle.done() #颜色填充 turtle.fillcolor('red') #开始填充 turtle.begin_fill() turtle.forward(100) turtle.goto(100,100) turtle.goto(0,100) turtle.goto(0,0) #结束填充 turtle.end_fill() turtle.color('black','green') turtle.begin_fill() turtle.circle(100) turtle.end_fill() turtle.done()