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

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

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

python自然编程生机勃勃的农场
让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() 


screen.mainloop()

下载完整源代码与素材,请

成为会员后,登陆才能继续浏览!联系微信scratch8即可办理会员。
(会员专属:能浏览所有文章,下载所有带链接的Python资源。)

李兴球

李兴球的博客是Python创意编程原创博客

评论已关闭。