Turtle graphics was originally meant for kids from 6 to 86. It was also used in robotics applications.
vegaseat
DaniWeb's Hypocrite
6,475 posts since Oct 2004
Reputation Points: 1,447
Solved Threads: 1,611
Skill Endorsements: 36
Another look at the Python module turtle:
# module turtle is part of Tkinter
# turtle starts in the center of canvas (0, 0) by default
# draw 3 turtle lines to form a triangle
import turtle as tu
tu.title('draw an equilateral triangle')
# set at 50% of original size
tu.setup(width=0.5, height=0.5)
# optional ...
# values for speed are 'fastest' (no delay), 'fast', (delay 5ms),
# 'normal' (delay 10ms), 'slow' (delay 15ms), 'slowest' (delay 20ms)
#tu.speed('fastest')
# optional ...
# turtle by default starts at (x=0, y=0) center of a (450x550) window
# to pick another center lift the pen up then move
# to the right x units and up y units or ...
# to the left -x units and down -y units
# now drop the pen down to start drawing
tu.up()
tu.goto(60, 100)
tu.down()
# optional pen color
tu.color('red')
# form a triangle by drawing 3 lines of 150 pixels length
# changing the direction by 120 degrees (360/3) each time
# starts at upper right corner and points down
for k in range(3):
tu.right(120)
tu.forward(150)
# keep showing until window corner x is clicked
tu.done()
Ene Uran
Posting Virtuoso
1,830 posts since Aug 2005
Reputation Points: 676
Solved Threads: 255
Skill Endorsements: 7
Just to see what it would take, modifying Ene's code to draw a right angle triangle of unknown dimensions is just a little more tedious
import turtle as tu
import random
tu.title('draw a right angle triangle')
# set at 50% of original size
tu.setup(width=0.5, height=0.5)
tu.up()
tu.goto(60, 100)
tu.down()
# optional pen color
tu.color('red')
hypotenuse=random.randint(100, 200)
base=random.randint(10, 99)
side = (hypotenuse**2 - base**2)**0.5
## round up the "old" way
side += 0.5
side = int(side)
for distance in (base, side):
tu.forward(distance)
tu.right(90)
## since we are using whole numbers, the sides will not be exact,
## so go to the starting point
tu.goto(60, 100)
# keep showing until window corner x is clicked
tu.done()
woooee
Posting Maven
2,706 posts since Dec 2006
Reputation Points: 827
Solved Threads: 779
Skill Endorsements: 9