Python-海龟绘图体系(turtle)

目录

  1. turtle库基本介绍
  2. turtle绘图窗体布局
  3. turtle空间坐标体系
  4. turtle角度坐标体系
  5. RGB色彩体系

turtle库基本介绍

turtle库是turtle绘图体系的Python实现,1969年诞生,主要用于程序设计入门

turtle绘图窗体布局

Python-海龟绘图体系(turtle)_第1张图片

turtle空间坐标体系

绝对坐标

Python-海龟绘图体系(turtle)_第2张图片

相对坐标(海龟坐标)

Python-海龟绘图体系(turtle)_第3张图片

turtle.circle(r, angle)中 r 是圆心,angle是角度,r为正数(负数),圆心在海龟左侧(右侧)r处,angle为正数(负数),绘制方向和海龟方向相同(相反);

import turtle

def reset():
    turtle.penup();
    turtle.goto(0,0);
    turtle.seth(0);
    turtle.pendown();
    
turtle.circle(50, 180);
reset();

turtle.pencolor('red');
turtle.circle(-50, 180);
reset();

turtle.pencolor('green');
turtle.circle(50, -180);
reset();

turtle.pencolor('blue');
turtle.circle(-50, -180);
reset();

运行结果如下图:

Python-海龟绘图体系(turtle)_第4张图片

turtle角度坐标体系

绝对角度

Python-海龟绘图体系(turtle)_第5张图片

相对角度(海龟角度)

Python-海龟绘图体系(turtle)_第6张图片

RGB色彩体系

Python-海龟绘图体系(turtle)_第7张图片

 

Python-海龟绘图体系(turtle)_第8张图片

Python-海龟绘图体系(turtle)_第9张图片

小练习:

import turtle

turtle.pensize(3);
ls = ['yellow', 'magenta', 'cyan', 'blue', 'black', 'seashell',\
      'gold', 'pink', 'brown', 'purple', 'tomato'];
for i in range(100):
    turtle.pencolor(ls[i%11]);
    turtle.fd(i*5);
    turtle.left(90);

运行结果:

Python-海龟绘图体系(turtle)_第10张图片

turtle.pensize(3);
ls = ['yellow', 'magenta', 'cyan', 'blue', 'black', 'seashell',\
      'gold', 'pink', 'brown', 'purple', 'tomato'];
for i in range(100):
    turtle.pencolor(ls[i%11]);
    turtle.fd(i*3);
    turtle.left(92);

运行结果:

Python-海龟绘图体系(turtle)_第11张图片

本文仅为学习Python记录,部分素材来源于中国大学MOOC《Python语言设计》—嵩天

你可能感兴趣的:(Python,turtle,Python)