python turtle画4个同心圆方法

Python012

python turtle画4个同心圆方法,第1张

import turtle

#draw first circle

turtle.penup()

turtle.goto(0,-200)

turtle.pendown()

turtle.circle(200)

#draw second circle

turtle.penup()

turtle.goto(0,-150)

turtle.pendown()

turtle.circle(150)

#draw third circle

turtle.penup()

turtle.goto(0,-100)

turtle.pendown()

turtle.circle(100)

#draw fourth circle

turtle.penup()

turtle.goto(0,-50)

turtle.pendown()

turtle.circle(50)

画笔坐标默认在0,0,就以它为圆心。

因为turtle画圆的时候是从圆的底部开始画的,所以需要找到四个圆底部的坐标

比如:

第一个半径为200的圆,底部为(0,-200)

第二个半径为150的圆,底部为(0,-150)

第三个半径为100的圆,底部为(0,-100)

第四个半径为  50的圆,底部为(0,  -50)

画的时候按下面的步骤:

抬起画笔:turtle.penup()

移动到相应坐标:turtle.goto(坐标)

放下画笔:turtle.pendown()

画圆:turtle.circle(半径)

效果如下图所示:

###################################

# coding=utf-8

# !/usr/bin/env python

# __author__ = 'pipi'

# ctime 2014.10.11

# 绘制椭圆和圆形

###################################

from matplotlib.patches import Ellipse, Circle

import matplotlib.pyplot as plt

fig = plt.figure()

ax = fig.add_subplot(111)

ell1 = Ellipse(xy = (0.0, 0.0), width = 4, height = 8, angle = 30.0, facecolor= 'yellow', alpha=0.3)

cir1 = Circle(xy = (0.0, 0.0), radius=2, alpha=0.5)

ax.add_patch(ell1)

ax.add_patch(cir1)

x, y = 0, 0

ax.plot(x, y, 'ro')

plt.axis('scaled')

# ax.set_xlim(-4, 4)

# ax.set_ylim(-4, 4)

plt.axis('equal') #changes limits of x or y axis so that equal increments of x and y have the same length

plt.show()

你可以试试,谢谢。