Welcome to Dream.In.Code
Getting Help is Easy!

Join 136,272 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,252 people online right now. Registration is fast and FREE... Join Now!




Turtle Graphics

 
Reply to this topicStart new topic

Turtle Graphics, Have you created any projects using the Tkinter Turtle?

dave_6_10
28 Aug, 2008 - 02:48 PM
Post #1

New D.I.C Head
Group Icon

Joined: 19 Mar, 2008
Posts: 28


Dream Kudos: 25
My Contributions
CODE

  goto(0,0)
  down()
  goto(25,0)
  goto(25,25)
  goto(0,25)
  goto(0,0)
  up()


Check this turtle out its a pretty basic that has some complex coolness.
User is offlineProfile CardPM
+Quote Post

baavgai
RE: Turtle Graphics
28 Aug, 2008 - 05:15 PM
Post #2

Dreaming Coder
Group Icon

Joined: 16 Oct, 2007
Posts: 2,019



Thanked: 105 times
Dream Kudos: 475
Expert In: C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua

My Contributions
You, um, made a square. tongue.gif

On of the most impresive learning tools I've seen in a long time is the Turtle Art program that comes with the OLPC machine. It uses interlocking code elements to show the student the basics of procedural programming.

I taught Terrapin Logo to kids grades second through fifth, many many years ago. The second graders started with squares. wink2.gif

User is offlineProfile CardPM
+Quote Post

dave_6_10
RE: Turtle Graphics
31 Aug, 2008 - 01:49 PM
Post #3

New D.I.C Head
Group Icon

Joined: 19 Mar, 2008
Posts: 28


Dream Kudos: 25
My Contributions
well, its hard to post something overly complex considering I only have an hour per each library computer session, I will try to post something a little more "advanced" tomorrow ")
User is offlineProfile CardPM
+Quote Post

dave_6_10
RE: Turtle Graphics
2 Sep, 2008 - 02:24 PM
Post #4

New D.I.C Head
Group Icon

Joined: 19 Mar, 2008
Posts: 28


Dream Kudos: 25
My Contributions
CODE

def drawcube():
    # A cube to give the illusion of 3 dimensions.
    cubex=-15
    cubey=-15
    plus8=+160
    minus4=-80
    minus5=-100
    color("yellow")
    goto(cubex,cubey)
    down()
    goto(cubex,cubey+plus8)
    goto(cubex+plus8,cubey+plus8)
    goto(cubex+plus8,cubey)
    goto(cubex+plus8+minus4,cubey+minus5)
    goto(cubex+minus4,cubey+minus5)
    goto(cubex+minus4,cubey+plus8+minus5)
    goto(cubex+plus8+minus4,cubey+plus8+minus5)
    goto(cubex+plus8,cubey+plus8)
    goto(cubex,cubey+plus8)
    goto(cubex+minus4,cubey+plus8+minus5)
    goto(cubex+minus4,cubey+minus5)
    goto(cubex,cubey)
    goto(cubex,cubey+plus8)
    goto(cubex,cubey)
    goto(cubex+plus8,cubey)
    goto(cubex+plus8+minus4,cubey+minus5)
    goto(cubex+plus8+minus4,cubey+plus8+minus5)
    up()
    color("black")
    goto(cubex,cubey)
    down()
    goto(cubex,cubey+plus8)
    goto(cubex+plus8,cubey+plus8)
    goto(cubex+plus8,cubey)
    goto(cubex+plus8+minus4,cubey+minus5)
    goto(cubex+minus4,cubey+minus5)
    goto(cubex+minus4,cubey+plus8+minus5)
    goto(cubex+plus8+minus4,cubey+plus8+minus5)
    goto(cubex+plus8,cubey+plus8)
    goto(cubex,cubey+plus8)
    goto(cubex+minus4,cubey+plus8+minus5)
    goto(cubex+minus4,cubey+minus5)
    goto(cubex,cubey)
    goto(cubex,cubey+plus8)
    goto(cubex,cubey)
    goto(cubex+plus8,cubey)
    goto(cubex+plus8+minus4,cubey+minus5)
    goto(cubex+plus8+minus4,cubey+plus8+minus5)
    color("green")
    up()
    goto(cubex,cubey)
    down()
    goto(cubex,cubey+plus8)
    goto(cubex+plus8,cubey+plus8)
    goto(cubex+plus8,cubey)
    goto(cubex+plus8+minus4,cubey+minus5)
    goto(cubex+minus4,cubey+minus5)
    goto(cubex+minus4,cubey+plus8+minus5)
    goto(cubex+plus8+minus4,cubey+plus8+minus5)
    goto(cubex+plus8,cubey+plus8)
    goto(cubex,cubey+plus8)
    goto(cubex+minus4,cubey+plus8+minus5)
    goto(cubex+minus4,cubey+minus5)
    goto(cubex,cubey)
    goto(cubex,cubey+plus8)
    goto(cubex,cubey)
    goto(cubex+plus8,cubey)
    goto(cubex+plus8+minus4,cubey+minus5)
    goto(cubex+plus8+minus4,cubey+plus8+minus5)
    up()
    
    sleep(1)


okay instead of a square lets try a cube. smile.gif

This one will be fun for your second graders also smile.gif
CODE


def engine():
    reset()
    up()
    #the letter "E"
    goto(40,70)
    down()
    goto(0,70)
    goto(0,10)
    goto(40,10)
    up()
    goto(40,40)
    down()
    goto(0,40)
    up()
    #the letter "E" moved to show a motion of entire shape of (-20,-20)
    color("green")
    goto(40-20,70-20)
    down()
    goto(0-20,70-20)
    goto(0-20,10-20)
    goto(40-20,10-20)
    up()
    goto(40-20,40-20)
    down()
    goto(0-20,40-20)
    up()
    #the letter "E" moved to show a motion of entire shape of (-20,-20)
    color("red")
    goto(40-40,70-40)
    down()
    goto(0-40,70-40)
    goto(0-40,10-40)
    goto(40-40,10-40)
    up()
    goto(40-40,40-40)
    down()
    goto(0-40,40-40)
    up()
    #the letter "E" moved to show a motion of entire shape of (-20,-20)
    color("maroon")
    goto(40-60,70-60)
    down()
    goto(0-60,70-60)
    goto(0-60,10-60)
    goto(40-60,10-60)
    up()
    goto(40-60,40-60)
    down()
    goto(0-60,40-60)
    up()
    #the letter "E" moved to show a motion of entire shape of (-20,-20)
    color("pink")
    goto(40-80,70-80)
    down()
    goto(0-80,70-80)
    goto(0-80,10-80)
    goto(40-80,10-80)
    up()
    goto(40-80,40-80)
    down()
    goto(0-80,40-80)
    
    sleep(2),
    

if __name__ == '__main__':

    engine()
    sleep(3)
    done()


CODE
#Bicyclewheel
    #As the rain falls I am thankful for the cooling aire.
    #The heat has been steadfast and tonight it breaks!
    speed("fastest")
    x=0
    y=0
    up()
    goto(x,y-50)
    down()
    fill(1)
    color("black")
    circle(50)
    fill(0)
    up()
    goto(x,y-40)
    down()
    color("white")
    fill(1)
    circle(40)
    fill(0)
    color("black")
    up()
    goto(x,y)
    down()
    goto(x+40,y)
    goto(x,y)
    goto(x-40,y)
    goto(x,y)
    goto(x,y+40)
    goto(x,y-40)
    goto(x,y)
    setheading(45)
    forward(40)
    backward(80)
    goto(x,y)
    setheading(135)
    forward(40)
    backward(80)
    
    up()
    sleep(1)
    reset()
    write("created by dave_6_10")


And this one is especially useful for the exploratory purpose of learning to use turtle graphix
User is offlineProfile CardPM
+Quote Post

baavgai
RE: Turtle Graphics
2 Sep, 2008 - 04:35 PM
Post #5

Dreaming Coder
Group Icon

Joined: 16 Oct, 2007
Posts: 2,019



Thanked: 105 times
Dream Kudos: 475
Expert In: C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua

My Contributions
Nice. For turtles, I like the classics:
CODE

from turtle import *

speed("fastest")
color("blue")
down()
for i in range(36):
    for j in range(10):
        forward(50)
        right(36)
    right(10)
up()


Also, I'm not fond of goto. It breaks the metaphor of a turtle taking some steps, dipping it's tail in paint, picking it up and putting it down. What does a turtle know of x and y? It only need know move and turn. Here's a cube without goto, by way of example:
CODE

def DrawCube(size, zsize, boxColor, sideColor):
    def square(size):
        down()
        for step in range(4):
            forward(size)
            right(90)
        up()

    def side(size, zsize):
        down()
        right(45)
        forward(zsize)
        left(45)
        forward(size)
        left(135)
        forward(zsize)
        left(45)
        forward(size)
        right(180)
        up()
        
    color(boxColor)
    square(size)
    color(sideColor)
    side(size, zsize)
    right(90)
    forward(size)
    left(90)
    side(size, zsize)
    left(90)
    forward(size)
    right(90)
    color(boxColor)
    square(size)
    up()
    right(45)
    forward(zsize)
    left(45)
    down()
    square(size)
    up()

DrawCube(150, 100, "black", "blue")


User is offlineProfile CardPM
+Quote Post

dave_6_10
RE: Turtle Graphics
5 Sep, 2008 - 09:51 AM
Post #6

New D.I.C Head
Group Icon

Joined: 19 Mar, 2008
Posts: 28


Dream Kudos: 25
My Contributions
Hey since your so Wizardours and full of knowledge in the python language maybe you could help me with fitting this whole character sheet into one window tongue.gif

DnD Charactersheet:
CODE

__author_="Dave_6_10"
__title_="Dungeons and Dragons character sheet"
__version_="1.0"


def page1():
    print("""
____________________________   _______________________________    Dungeons
CHARACTER NAME                 PLAYER                           ==>-&-----
____________________________   ___________ ___________ _________  Dragons
CLASS AND LEVEL                RACE        AUGMENT     DEITY
_______  _______  ______  _______ _______ _________ _________ _________
size     age      gender  height  weight  eyes      hair      skin

Ability Name|Ability    Ability   Temporary   Temporary
            | score   | modifier   score      modifier
  Strength  |_________|_________|___________|__________|
  Dexterity |_________|_________|___________|__________|
Constitution|_________|_________|___________|__________|
Intelligence|_________|_________|___________|__________|
   Wisdom   |_________|_________|___________|__________|
  Charisma  |_________|_________|___________|__________|
Hit Points |_________|_________|___________|__________|

""")
    stop=int(input("enter 1 to go to next page"))
    page=stop
    if page == 1: exec('page2()')

def page2():
    print("""
                        --------------   ------------------------------
_______________________|  FEATS       | |         SPELLS              |
Campaign               |--------------| |---Domain/Specialty School---|
|----------------------|______________| |_____________________________|
|______________________|______________| |_____________________________|
Exp Points             |              | |o:___________________________|
                       |______________| |                             |
        GEAR           |              | |_____________________________|
""")
    stop=int(input("enter 1 to go to next page"))
    page=stop
    if page == 1: exec('page2()')

if __name__ == '__main__':
          page1()

User is offlineProfile CardPM
+Quote Post

baavgai
RE: Turtle Graphics
6 Sep, 2008 - 11:43 AM
Post #7

Dreaming Coder
Group Icon

Joined: 16 Oct, 2007
Posts: 2,019



Thanked: 105 times
Dream Kudos: 475
Expert In: C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua

My Contributions
Define window. The code you've shown merely dumps text to a screen. If it's a terminal window, define more rows. You're limited by your environment, not the language.

Design it in a word processor, dump it to a PDF. Make an image and display the image. If you want to interact with the user, then it becomes more interesting.

Personally, I'd use HTML. It's ubiquitous, understood by most users, easy to enter data into and print from.

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 04:57AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month