Skip to main content

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

  1. draw_poly
  2. draw_line
  3. 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)

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

turtex-0.0.3.tar.gz (4.3 kB view hashes)

Uploaded Source

Built Distribution

turtex-0.0.3-py3-none-any.whl (4.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page