生机勃勃的农场_ 花花草草的小世界

让Python程序描述一下大自然,本程序更关键的是要有好的素材与搭配等.

"""
   生机勃勃的农场.py
   太阳升起来了,绿茵草地上的花朵们充满生机,小狗在来会走动,还有发财树在等着你去摇一摇.
"""
import os
from turtle import *
from animation import *
from time import sleep
from random import choice,randint
from sprite import Sprite as Karaoke


"""一、新建屏幕,如需要渐变效果,需要许多张背景图切换"""
width,height = 1024,768
halfwidth,halfheight = width//2,height//2
screen = Screen()
screen.delay(0)
screen.setup(width,height)
screen.bgcolor("black")
sleep(1)
screen.bgpic("background.png")
screen.title("我的农场")


"""二、画太阳"""
draw_turtle = Turtle(visible=False,shape='circle')
draw_turtle.penup()
draw_turtle.goto(250,-250)
draw_turtle.color("red","red")
draw_turtle.shapesize(5,5)
draw_turtle.st()
for i in range(50):
    draw_turtle.sety(draw_turtle.ycor() + 10)
    draw_turtle.stamp()
    sleep(0.01)
    draw_turtle.clear()
    screen.update()

draw_turtle.stamp()
draw_turtle.ht()
for i in range(12):
    draw_turtle.fd(100)
    draw_turtle.pendown()
    draw_turtle.fd(50)
    draw_turtle.penup()
    draw_turtle.bk(150)
    draw_turtle.right(30)
    sleep(0.01)


"""三、花的动画"""
cwd = os.getcwd() + os.sep

f0path = cwd + "花" + os.sep + "淡黄花" + os.sep
flower0_images = [f0path + "黄"+ str(i) + ".gif" for i in range(1,7)] 
[screen.addshape(image) for image in flower0_images]  #注册到屏幕形状列表
flower0 = Animation(flower0_images,400,-200,200)         
flower0.alt_image() 

f1path = cwd + "花" + os.sep + "橘花" + os.sep
flower1_images = [f1path + "橘花"+ str(i) + ".gif" for i in range(1,7)]
[screen.addshape(image) for image in flower1_images]  #注册到屏幕形状列表
flower1 = Animation(flower1_images,200,-230,200)  
flower1.alt_image()
 
f2path = cwd + "花" + os.sep + "蓝花" + os.sep
flower2_images = [f2path + "蓝花"+ str(i) + ".gif" for i in range(1,7)] 
[screen.addshape(image) for image in flower2_images]       
flower2 = Animation(flower2_images,0,-230,200)              
flower2.alt_image()                      

f3path = cwd + "花" + os.sep + "紫花" + os.sep
flower3_images = [f3path + "紫" + str(i) + ".gif" for i in range(1,7)] 
[screen.addshape(image) for image in flower3_images]  #注册到屏幕形状列表
flower3 = Animation(flower3_images,-200,-230,200)       
flower3.alt_image()

 
"""四、画房子"""
draw_turtle.pencolor("black")
draw_turtle.pensize(10)
draw_turtle.goto(0,0)
draw_turtle.setheading(-45)
draw_turtle.pendown()
draw_turtle.fd(100)
draw_turtle.bk(100)
draw_turtle.right(90)
draw_turtle.fd(100)
draw_turtle.setheading(0)
draw_turtle.fd(20)
draw_turtle.setheading(270)
draw_turtle.fd(60)
draw_turtle.setheading(0)
draw_turtle.fd(100)
draw_turtle.setheading(90)
draw_turtle.fd(60)
draw_turtle.setheading(0)
draw_turtle.fd(20)
draw_turtle.shape('square')
draw_turtle.color("black","black")
draw_turtle.shapesize(1,1)
draw_turtle.penup()
draw_turtle.goto(-20,-80)
draw_turtle.stamp()
draw_turtle.goto(20,-80)
draw_turtle.stamp()
draw_turtle.goto(20,-110)
draw_turtle.stamp()
draw_turtle.goto(-20,-110)
draw_turtle.stamp()

"""五、生成狗"""
dog_images_folder =  os.getcwd() + os.sep + "dog_gif" + os.sep
images0 = []             #左造型列表
images0.append(dog_images_folder +  "dog2-a_L.gif")
images0.append(dog_images_folder +  "dog2-b_L.gif")
images0.append(dog_images_folder +  "dog2-c_L.gif")

images1 = []             #右造型列表
images1.append(dog_images_folder +  "dog2-a.gif")
images1.append(dog_images_folder +  "dog2-b.gif")
images1.append(dog_images_folder +  "dog2-c.gif")
 
[screen.addshape(image ) for image in images0]
[screen.addshape(image ) for image in images1]  

Karaoke(-200,images0,images1)


"""六、树的动画"""
tree_gif_folder = os.getcwd() + os.sep + "tree_gif" + os.sep
#树的造型表
tree_images = [tree_gif_folder + str(i) + ".gif" for i in range(2)]
[screen.addshape(image) for image in tree_images]      #注册到屏幕形状列表
tree = Animation(tree_images,-400,-200,100)            #生成树 
tree.alt_image()

screen.mainloop()

python自然编程生机勃勃的农场