import turtle
import random
myPen = turtle.Turtle()
myPen.tracer(0)
myPen.speed(0)
screen = turtle.Screen()
#Blue Sky
screen.bgcolor("#0060E6")
#A procedure to trace the skyline using a polynomiale function:
def drawSkyline(color):
global a,b,c,d
myPen.penup()
myPen.goto(-200,-200)
myPen.color(color)
myPen.pendown()
myPen.fillcolor(color)
myPen.begin_fill()
#Trace the skyline, 1 pixel at a time, from left (x=-200) to right (x=200)
for x in range(-200,201):
y = a*x**3 + b*x**2 + c*x + d
myPen.goto(x,y)
myPen.goto(200,-200)
myPen.goto(-200,-200)
myPen.end_fill()
myPen.penup()
def addTree(color):
global a,b,c,d
x = random.randint(-200,200)
y = a*x**3 + b*x**2 + c*x + d
myPen.penup()
myPen.goto(x,y)
myPen.pensize(3)
myPen.color("#753707")
myPen.pendown()
myPen.goto(x,y+10)
myPen.color(color)
myPen.fillcolor(color)
myPen.pensize(1)
myPen.begin_fill()
myPen.circle(15)
myPen.end_fill()
# Main Program Starts Here
#Randomly generate coefficients for our polynomial function
a = random.randint(-20,20)/(100**3)
b = random.randint(-20,20)/(100**2)
c = random.randint(-20,20)/100
d = random.randint(-20,20)
#Draw the skyline using the polynomial function
drawSkyline("green")
#Add Trees
for i in range(0,random.randint(2,5)):
addTree("#065900")
addTree("#2B7A26")
myPen.hideturtle()
screen.tracer(0)
myPen.getscreen().update()
-----------------
Nincsenek megjegyzések:
Megjegyzés küldése