Sea shells animation and text graphic

jib 1 Tallied Votes 365 Views Share

code and tutorials are abvoe

###################################
# PROLOG SECTION
# sea_shells.py
# Draws a simple sea shell using Python Turtle Graphics.
#
# Tested with Python 2.6.1
# May 23, 2009
#
# Copyright 2009 National Academy Foundation. All rights reserved.
#
# Possible future enhancements:
# Unresolved bugs:
###################################

###################################
# ENVIRONMENT SETUP SECTION
# Imports: turtle, time, ramdom
###################################

# import turtle drawing routine
from turtle import *

# import time routines
from time import sleep

# import random routines
from random import *

###################################
# FUNCTION DEFINITION SECTION
# Definitions: draw_shell()
###################################

def draw_shell(thecolor,myturtle, x, y):
        myturtle.up()
        myturtle.goto(x,y)
        myturtle.down()
        # set the pen color, which is chosen randomly
        myturtle.color(thecolor)
        # set the pen width
        myturtle.width(2)
        # set the drawing speed
        myturtle.speed("fastest")
        # hide the turtle while it draws the circles
        myturtle.hideturtle()

        for radius in range(1,220,5):
                # increase the heading angle as the radius increases
                angle = radius - 1
                # set the turtle heading
                myturtle.setheading(angle)
                # draw the next circle
                myturtle.circle(radius)

        # wait before erasing all the circles
        sleep(1)

        # erase the circles we just drew
        myturtle.color("white")
        for radius in range(216,1,-5):
                # decrease the heading angle as the radius decreases
                angle = radius - 1
                # set the turtle heading
                myturtle.setheading(angle)
                # erase the next circle
                myturtle.circle(radius)      
        
###################################
# PROCESSING INITIALIZATION SECTION
###################################

# create the drawing window
setup()

# create a title for the drawing window
title("sea shells program")

# create the drawing turtle
myturtle=Turtle()

# define the tuple of colors
shell_colors = ("red","blue","green","pink","yellow","black","brown","purple")

###################################
# PROCESSING SECTION
# Call the shell draw/erase function
###################################

# set the shell color for this iteration of the shell
thecolor = choice(shell_colors)
# draw and erase the sea shell
draw_shell(thecolor,myturtle,0,50)

# wait a bit
sleep(1)

# set the shell color for this iteration of the shell
thecolor = choice(shell_colors)
# draw and erase the sea shell
draw_shell(thecolor,myturtle,100,150)

###################################   
# CLEANUP, TERMINATION, AND EXIT SECTION
###################################

done()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.