9 Replies - 1326 Views - Last Post: 25 February 2013 - 05:51 PM Rate Topic: -----

#1 snow_ninja67  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 46
  • Joined: 29-January 13

How to set speed?

Posted 25 February 2013 - 01:52 PM

Hello all,

so im doing a HW project and i want to do a little extra like let the user input the speed of the arrow drawing here is my current code:
from turtle import *

#function Variables
space_width = int(input("Enter a number for the space width between 10-30:")) # Default value: 30
letter_height = int(input("Enter a number for the height between 50-100:")) # Default value: 100
letter_width = int(input("Enter a number for the letter width between 10-50:")) # Default value: 50
pen_color = input("Enter a color:")
pen_width = input("Enter a number from 1-10:")
#pickup the turtle and move it to the x and y cordinates.
penup()
goto(-200, 100)
pendown()

def draw_space():
    # Add a space 30 pixels wide.
    penup()
    forward(space_width)
    pendown()

def draw_H():
    # Draw the left leg of the H.
    # The turtle starts at the bottom left of the letter, pointing right.
    left(90)
    forward(letter_height)
    # Draw the bar of the H.
    # The turtle starts at the top of the left leg, pointing up.
    forward(-letter_height / 2)
    right(90)
    forward(letter_width)
    # Draw the right leg of the H.
    # The turtle starts on the right side of the bar, pointing right.
    left(90)
    forward(letter_height / 2)
    forward(-letter_height)
    right(90)
    # The H is drawn.
    # The turtle is at the bottom right, pointing right.
    #next it adds a space
    draw_space()

def draw_E():
    #Draw an E.
    left(90)
    forward(letter_height)
    right(90)
    forward(letter_width)
    forward(-letter_width)
    right(90)
    forward(letter_height / 2)
    left(90)
    forward(letter_width)
    forward(-letter_width)
    right(90)
    forward(letter_height / 2)
    left(90)
    forward(letter_width)
    #next it adds a space
    draw_space()
def draw_L():
    # Draw the L
    left(90)
    forward(letter_height)
    forward(-letter_height)
    right(90)
    forward(letter_width)
    draw_space()
def draw_O():
    # Draw the O.
    forward(letter_width)
    left(90)
    forward(letter_height)
    left(90)
    forward(letter_width)
    left(90)
    forward(letter_height)
    left(90)
    forward(letter_width)
    draw_space()
color(pen_color)
width(pen_width)
draw_H()
draw_E()
draw_L()
draw_L()
draw_O()
exitonclick()



thank you :D

Is This A Good Question/Topic? 0
  • +

Replies To: How to set speed?

#2 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3809
  • View blog
  • Posts: 13,519
  • Joined: 12-December 12

Re: How to set speed?

Posted 25 February 2013 - 02:14 PM

You have set practically every other property of the turtle, so why would setting the speed() be any more difficult?

At least attempt it and come back if you need help.
Was This Post Helpful? 1
  • +
  • -

#3 snow_ninja67  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 46
  • Joined: 29-January 13

Re: How to set speed?

Posted 25 February 2013 - 02:51 PM

View Postandrewsw, on 25 February 2013 - 02:14 PM, said:

You have set practically every other property of the turtle, so why would setting the speed() be any more difficult?

At least attempt it and come back if you need help.

sorry XD didn't think it was that simple i did self._speed = 3 and that didn't work so that's why i was wondering and it tied turtle_speed() BTW u gave the answer to my question so thanks! :D/>/>
PS in the lesson it didn't mention how to set speed so i went into python 32 libs folder and went to turtle and tried to look for the proper input and saw self._speed = 3 thats why i was asking.
Was This Post Helpful? 0
  • +
  • -

#4 snow_ninja67  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 46
  • Joined: 29-January 13

Re: How to set speed?

Posted 25 February 2013 - 02:56 PM

Also can you please explain why you sometimes have to use
int(input(""))
or a
input("")
?

is
int(input(""))
integer input?
while
(input(""))
is just a normal input?
Was This Post Helpful? 0
  • +
  • -

#5 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3809
  • View blog
  • Posts: 13,519
  • Joined: 12-December 12

Re: How to set speed?

Posted 25 February 2013 - 03:01 PM

the docs is the first place to look, or help(turtle) perhaps.

You should use turtle.speed(3) as _speed is intended to be a private variable.

input("Some prompt") always return a string (text). int(input("Some prompt")) attempts to convert the text to an integer number.

This post has been edited by andrewsw: 25 February 2013 - 02:59 PM

Was This Post Helpful? 0
  • +
  • -

#6 snow_ninja67  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 46
  • Joined: 29-January 13

Re: How to set speed?

Posted 25 February 2013 - 03:01 PM

View Postandrewsw, on 25 February 2013 - 02:57 PM, said:

the docs is the first place to look, or help(turtle) perhaps.

You should use turtle.speed(3) as _speed is intended to be a private variable.

Gah dammmmm u sonic wall (i cant access the docs D
but other tank you so much
Was This Post Helpful? 0
  • +
  • -

#7 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3809
  • View blog
  • Posts: 13,519
  • Joined: 12-December 12

Re: How to set speed?

Posted 25 February 2013 - 03:03 PM

Quote

turtle.speed(speed=None)
Parameters: speed – an integer in the range 0..10 or a speedstring (see below)
Set the turtle’s speed to an integer value in the range 0..10. If no argument is given, return current speed.

If input is a number greater than 10 or smaller than 0.5, speed is set to 0. Speedstrings are mapped to speedvalues as follows:

“fastest”: 0
“fast”: 10
“normal”: 6
“slow”: 3
“slowest”: 1
Speeds from 1 to 10 enforce increasingly faster animation of line drawing and turtle turning.

Attention: speed = 0 means that no animation takes place. forward/back makes turtle jump and likewise left/right make the turtle turn instantly.

Was This Post Helpful? 0
  • +
  • -

#8 snow_ninja67  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 46
  • Joined: 29-January 13

Re: How to set speed?

Posted 25 February 2013 - 03:41 PM

View Postandrewsw, on 25 February 2013 - 03:03 PM, said:

Quote

turtle.speed(speed=None)
Parameters: speed – an integer in the range 0..10 or a speedstring (see below)
Set the turtle’s speed to an integer value in the range 0..10. If no argument is given, return current speed.

If input is a number greater than 10 or smaller than 0.5, speed is set to 0. Speedstrings are mapped to speedvalues as follows:

“fastest”: 0
“fast”: 10
“normal”: 6
“slow”: 3
“slowest”: 1
Speeds from 1 to 10 enforce increasingly faster animation of line drawing and turtle turning.

Attention: speed = 0 means that no animation takes place. forward/back makes turtle jump and likewise left/right make the turtle turn instantly.

Thank you so much
Was This Post Helpful? 0
  • +
  • -

#9 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3809
  • View blog
  • Posts: 13,519
  • Joined: 12-December 12

Re: How to set speed?

Posted 25 February 2013 - 03:49 PM

No worries. Don't forget to:

turtle.feed("lettuce")

or is this only for a tortoise..
Was This Post Helpful? 0
  • +
  • -

#10 snow_ninja67  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 46
  • Joined: 29-January 13

Re: How to set speed?

Posted 25 February 2013 - 05:51 PM

View Postandrewsw, on 25 February 2013 - 03:49 PM, said:

No worries. Don't forget to:

turtle.feed("lettuce")

or is this only for a tortoise..

also would you liek to try to optimize a plugin for me? (Minecraft im an owner of a server and Ticks Per seconds drop to 5-12 out of 20). if you can big help :D
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1