海龟基础教学(八)——基础应用(二)

代码:

from turtle import *
colors = ["red", "orange", "yellow", "blue", "cyan", "lime", "pink", "purple"]
bgcolor("black")
x = 6
t = [Turtle(), Turtle()]
for index, i in enumerate(t):
    i.speed(0)
    i.color("white")
    i.shape("circle")
    i.shapesize(0.3)
    i.width(3)
    i.pu()
    i.seth(90)
    i.fd(350)
    i.seth(-180)
    i.pd()
t[0].pu()
delay(0)
speed(0)
ht()
for i in colors:
    color(i)
    for i in range(360):
        t[0].fd(x)
        t[0].lt(1)
        pu()
        goto(t[0].pos())
        pd()
        t[1].fd(2 * x)
        t[1].lt(2)
        goto(t[1].pos())
done()

效果图(动图):

代码:

import turtle
import math
colorList = ["red", "darkgreen", "purple", "violet", "gold"]
turtleList = []
for i in range(5):
    turtleList.append(turtle.Turtle(shape='turtle'))
for i in range(5):
    turtleList[i].color(colorList[i])
    turtleList[i].pensize(3)
turtleList[0].setposition(100*math.cos(math.pi/10), 100*math.sin(math.pi/10))
turtleList[0].lt(180)
turtleList[1].setposition(0, 100)
turtleList[1].rt(108)
turtleList[2].setposition(-100*math.cos(math.pi/10), 100*math.sin(math.pi/10))
turtleList[2].rt(36)
turtleList[3].setposition(-100*math.cos(3*math.pi/10), -
                          100*math.sin(3*math.pi/10))
turtleList[3].lt(36)
turtleList[4].setposition(
    100*math.cos(3*math.pi/10), -100*math.sin(3*math.pi/10))
turtleList[4].lt(108)
for i in range(int(200*math.cos(math.pi/10))):
    for j in range(5):
        turtleList[j].fd(1)
turtle.done()

效果图:

代码:

import turtle as t;import time as m;t.speed(100);t.ht();t.begin_fill();t.fillcolor("black");t.circle(-100,180);t.circle(-50,180);t.circle(50,180);t.end_fill();t.circle(100,180);t.up();t.home();t.goto(0,-50);t.dot(30,"black");t.goto(0,-150);t.dot(30,"white");m.sleep(6);t.done()

效果图:

代码:

from turtle import *
from random import random, randint
screen = Screen()
width, height = 800, 600
screen.setup(width, height)
screen.bgcolor("black")
screen.mode("logo")
screen.delay(0)
t = Turtle(visible=False, shape='circle')
t.pencolor("white")
t.fillcolor("white")
t.penup()
t.setheading(-90)
t.goto(width / 2, randint(-height / 2, height / 2))
stars = []
for i in range(200):
    star = t.clone()
    s = random() / 3
    star.shapesize(s, s)
    star.speed(int(s * 10))
    star.setx(width/2+randint(1, width))
    star.sety(randint(-height/2, height/2))
    star.showturtle()
    stars.append(star)
while True:
    for star in stars:
        star.setx(star.xcor() - 3 * star.speed())
        if star.xcor() < -width / 2:
            star.hideturtle()
            star.setx(width / 2 + randint(1, width))
            star.sety(randint(-height / 2, height / 2))
            star.showturtle()

效果图(动图):


版权声明:本文为a31203254602315原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。