Extension to turtle module.
Project description
Turtex
This is an extension for the built-in turtle module. It provides functions for ease of development.
Installation
Run the following to install:
pip install turtex
Usage
Different Functions
- draw_poly
- draw_line
- draw_x
draw_poly(number_of_sides, length, turtle_obj = None)
Draws regular polygons (shapes) from the current position which will become the bottom left / top right corner of the shape (It depends on the orientation of the turtle).
| Arguments | Description |
|---|---|
| number_of_sides | An integer indicating number of sides of the polygon to be drawn. |
| length | An integer indicating the length of each side in pixels. |
| turtle_obj | A turtle object to draw with. The default value is the default turtle in the turtle module. |
Implementation
import turtex
# Configure the turtle to draw different coloured lines and of different thickness.
t = turtex.Turtle()
t.pensize(5)
t.color("black")
# The following code draws a pentagon (shape with 5 sides) with each side of length 15 using t as turtle_obj.
turtex.draw_poly(5, 15, t)
draw_line(start_pos, length, direction_in_angle, turtle_obj = None)
Draws a line from a given point. Turtle object remains at the end of the line after drawing it.
| Arguments | Description |
|---|---|
| start_pos | A list/tuple indicating the starting position of the line. |
| length | An integer or float indicating the length of the line in pixels. |
| direction_in_angle | An integer or float indicating the direction of the line in degrees. Follow table below for general directions. |
| turtle_obj | A turtle object to draw with. The default value is the default turtle in the turtle module. |
| Standard Mode | Logo Mode |
|---|---|
| 0 - East | 0 - North |
| 90 - North | 90 - East |
| 180 - West | 180 - South |
| 270 - South | 270 - West |
Implementation
import turtex
# Configure the turtle to draw different coloured line and of different thickness.
t = turtex.Turtle()
t.pensize(5)
t.color("black")
# The following code produces a line from (0, 0) of 50 length at 90 degrees(North) using t as turtle_obj.
turtex.draw_line((0, 0), 50, 90, t)
draw_x(start_pos, length, line_colour_top_left, line_colour_top_right, line_colour_bottom_left, line_colour_bottom_right, turtle_obj = None)
Draws an 'x' shape.
| Arguments | Description |
|---|---|
| start_pos | A list/tuple indicating the starting position of the 'x'. This is the center of the 'x'. |
| length | An integer or float indicating the length of each line in pixels. |
| line_colour_top_left | A list/tuple of rgb values if the colormode is 255 else a string indicating the colour of the top left line. |
| line_colour_top_right | A list/tuple of rgb values if the colormode is 255 else a string indicating the colour of the top right line. |
| line_colour_bottom_left | A list/tuple of rgb values if the colormode is 255 else a string indicating the colour of the bottom left line. |
| line_colour_bottom_right | A list/tuple of rgb values if the colormode is 255 else a string indicating the colour of the bottom right line. |
| turtle_obj | A turtle object to draw with. The default value is the default turtle in the turtle module. |
Implementation
import turtex
# Configure the turtle to draw lines of different thickness.
t = turtex.Turtle()
t.pensize(5)
# The following code produces a line from (0, 0) of 50 length with
# colors red, orange, yellow, green for the top_left, top_right, bottom_left,
# bottom_right lines respectively using t as turtle_obj.
turtex.draw_x((0, 0), 50, "red", "orange", "yellow", "green", t)
# Changing colormode to enter colors in rgb values.
turtex.colormode(255)
turtex.draw_x((0, 0), 50, (255, 0, 0), (255, 127, 0), (255, 255, 0), (0, 255, 0), t)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file turtex-0.0.3.tar.gz.
File metadata
- Download URL: turtex-0.0.3.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
062633cd7d1f48d85b251592939e4872b21f112aba4980a815812fe20d9187a2
|
|
| MD5 |
a42463ba480e40ee20f2afb09096d37e
|
|
| BLAKE2b-256 |
c115b5885491c268f4831c3d0215cf864a1e80794e64e5e5bcda0b85e7d05469
|
File details
Details for the file turtex-0.0.3-py3-none-any.whl.
File metadata
- Download URL: turtex-0.0.3-py3-none-any.whl
- Upload date:
- Size: 4.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a8209e36fd754ffeaacfbfc39c84819293373fa09da39205a08b8b5fca86123a
|
|
| MD5 |
fd68e57207ef94d054ba20d77680b1eb
|
|
| BLAKE2b-256 |
be7d93fea2d960cffec2127c52c151a1784bae677d1314ac130ccd66cb0e955f
|