Skip to content

Instantly share code, notes, and snippets.

@Cartroo
Last active August 29, 2015 14:16
Show Gist options
  • Save Cartroo/b2ad2c2190f1fad31b7a to your computer and use it in GitHub Desktop.
Save Cartroo/b2ad2c2190f1fad31b7a to your computer and use it in GitHub Desktop.
Code Club: Turtle Scene
from math import *
from random import *
from turtle import *
def grass():
color("ForestGreen")
begin_fill()
forward(5000)
for i in range(3):
right(90)
forward(10000)
right(90)
forward(5000)
end_fill()
def sun_centre():
color("Yellow")
width(1)
forward(50)
right(90)
begin_fill()
for i in range(90):
forward(3.5)
right(4)
end_fill()
left(90)
backward(50)
def sun_spikes():
color("Gold")
width(5)
for i in range(24):
forward(80)
backward(80)
right(15)
def sun():
sun_spikes()
sun_centre()
def cloud():
color("White")
begin_fill()
old_pos = pos()
for i in range(3):
for j in range(60):
left(4)
forward(3.5)
right(180)
left(180)
setpos(*old_pos)
end_fill()
def tree(branchLen):
old_color = color()
old_width = width()
if branchLen >= 20:
color("brown")
width(branchLen / 5.0)
elif branchLen >= 10:
color((0.0, random() / 2.0 + 0.5, 0.0))
width(5)
else:
return
forward(branchLen)
right(60)
for i in range(4):
tree(int(branchLen / 1.5))
left(40)
right(100)
backward(branchLen)
width(old_width)
color(*old_color)
# Sky and grass
bgcolor("SkyBlue")
speed(0)
delay(0)
hideturtle()
grass()
# Sun
up()
setpos(100, 200)
down()
sun()
# Cloud
up()
setpos(50, 100)
down()
cloud()
# Tree
up()
setpos(-100, -100)
setheading(90)
down()
tree(80)
done()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment