Package: turtex
TurtexThis is an extension for the built-in turtle module. It provides functions for ease of development.InstallationRun the following to install:pipinstallturtexUsageDifferent Functionsdraw_polydraw_linedraw_xdraw_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).ArgumentsDescriptionnumber_of_sidesAn integer indicating number of sides of the polygon to be drawn.lengthAn integer indicating the length of each side in pixels.turtle_objA turtle object to draw with. The default value is the default turtle in the turtle module.Implementationimportturtex# 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.ArgumentsDescriptionstart_posA list/tuple indicating the starting position of the line.lengthAn integer or float indicating the length of the line in pixels.direction_in_angleAn integer or float indicating the direction of the line in degrees. Follow table below for general directions.turtle_objA turtle object to draw with. The default value is the default turtle in the turtle module.Standard ModeLogo Mode0 - East0 - North90 - North90 - East180 - West180 - South270 - South270 - WestImplementationimportturtex# 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.ArgumentsDescriptionstart_posA list/tuple indicating the starting position of the 'x'. This is the center of the 'x'.lengthAn integer or float indicating the length of each line in pixels.line_colour_top_leftA list/tuple of rgb values if the colormode is 255 else a string indicating the colour of the top left line.line_colour_top_rightA list/tuple of rgb values if the colormode is 255 else a string indicating the colour of the top right line.line_colour_bottom_leftA list/tuple of rgb values if the colormode is 255 else a string indicating the colour of the bottom left line.line_colour_bottom_rightA list/tuple of rgb values if the colormode is 255 else a string indicating the colour of the bottom right line.turtle_objA turtle object to draw with. The default value is the default turtle in the turtle module.Implementationimportturtex# 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)