pensize() 函数的示例

import turtle

step=100

turtle.penup()

turtle.setposition(-400, 0)

turtle.pendown()

turtle.speed(1)

turtle.write(0.001)

turtle.pensize(0.001)

turtle.forward(step)

turtle.write(0.01)

turtle.pensize(0.01)

turtle.forward(step)

turtle.write(0.01)

turtle.pensize(0.1)

turtle.forward(step)

turtle.write(1)

turtle.pensize(1)

turtle.forward(step)

turtle.write(10)

turtle.pensize(10)

turtle.forward(step)

turtle.write(100)

turtle.pensize(100)

turtle.forward(step)

#turtle.write(1000)

#turtle.pensize(1000)

#turtle.forward(step)

turtle.done()

 

 可以看出最小是1像素,最大不限制。

 

turtle 可以用的全部颜色(所有颜色)

 

 

 

 

matplotlib 颜色名称

"""

========================

Visualizing named colors

========================

Simple plot example with the named colors and its visual representation.

"""

from __future__ import division

import matplotlib.pyplot as plt

from matplotlib import colors as mcolors

colors = dict(mcolors.BASE_COLORS, **mcolors.CSS4_COLORS)

# Sort colors by hue, saturation, value and name.

by_hsv = sorted((tuple(mcolors.rgb_to_hsv(mcolors.to_rgba(color)[:3])), name)

for name, color in colors.items())

sorted_names = [name for hsv, name in by_hsv]

n = len(sorted_names)

ncols = 4

nrows = n // ncols + 1

fig, ax = plt.subplots(figsize=(8, 5))

# Get height and width

X, Y = fig.get_dpi() * fig.get_size_inches()

h = Y / (nrows + 1)

w = X / ncols

for i, name in enumerate(sorted_names):

col = i % ncols

row = i // ncols

y = Y - (row * h) - h

xi_line = w * (col + 0.05)

xf_line = w * (col + 0.25)

xi_text = w * (col + 0.3)

ax.text(xi_text, y, name, fontsize=(h * 0.8),

horizontalalignment='left',

verticalalignment='center')

ax.hlines(y + h * 0.1, xi_line, xf_line,

color=colors[name], linewidth=(h * 0.6))

ax.set_xlim(0, X)

ax.set_ylim(0, Y)

ax.set_axis_off()

fig.subplots_adjust(left=0, right=1,

top=1, bottom=0,

hspace=0, wspace=0)

plt.show()

 

画图速度 turtle.speed()

import turtle

step=200

turtle.penup()

turtle.setposition(-400, 0)

turtle.pendown()

turtle.speed(1)

turtle.forward(step)

turtle.speed(5)

turtle.forward(step)

turtle.speed(10)

turtle.forward(step)

turtle.speed(100)

turtle.forward(step)

turtle.speed(0)

turtle.forward(step)

turtle.done()

 

五星红旗,五角星

import turtle

turtle.setup(600,400,0,0)

turtle.bgcolor("red")

turtle.fillcolor("yellow")

turtle.color('yellow')

turtle.speed(10)

#主星

turtle.begin_fill()

turtle.up()

turtle.goto(-280,100)

turtle.down()

for i in range (5):

turtle.forward(150)

turtle.right(144)

turtle.end_fill()

#第1颗副星

turtle.begin_fill()

turtle.up()

turtle.goto(-100,180)

turtle.setheading(305)

turtle.down()

for i in range (5):

turtle.forward(50)

turtle.left(144)

turtle.end_fill()

#第2颗副星

turtle.begin_fill()

turtle.up()

turtle.goto(-50,110)

turtle.setheading(30)

turtle.down()

for i in range (5):

turtle.forward(50)

turtle.right(144)

turtle.end_fill()

#第3颗副星

turtle.begin_fill()

turtle.up()

turtle.goto(-40,50)

turtle.setheading(5)

turtle.down()

for i in range (5):

turtle.forward(50)

turtle.right(144)

turtle.end_fill()

#第4颗副星

turtle.begin_fill()

turtle.up()

turtle.goto(-100,10)

turtle.setheading(300)

turtle.down()

for i in range (5):

turtle.forward(50)

turtle.left(144)

turtle.end_fill()

turtle.done()

 

查看原文