I would like to share a TinyTurtle graphics module I've written for the HP Prime. It is a lightweight implementation of the classic Python turtle module, optimized for the calculator's environment.

The module features two distinct operating modes:
  • Standard Mode: This is the traditional mode where drawing is performed directly on the screen in real time. It allows for control over the drawing speed, making it ideal for animations.
  • Viewport Mode: In this mode, the image is first rendered at maximum speed into a back buffer (ignoring speed commands). Once rendering is complete, the final image is displayed as a whole, allowing the user to scale and pan using single key presses.

There are three built-in grid types to assist with layout:
  • Dotted
  • Square
  • Triangular

The implementation is written entirely in Python, but despite that, it performs quite reasonably well from a performance perspective (many optimizations have been applied).
A strong emphasis has been placed on compatibility with the CPython Turtle API, making it possible to run most turtle scripts available online on the HP Prime.
The most significant limitation is that only a single turtle can exist on the screen at a time. Additionally, event handling (such as ontimer, onclick, etc.) is not supported. Nevertheless, functionality directly related to graphical rendering should work reliably.

Details on unsupported features are described in the documentation.

Below are a few examples of graphics generated using this module:










Viewport mode example:



Download: http://ceme.tech/DL2776
This is really cool! So glad there's a graphics library that can take advantage of the primes speed.
Version 0.92 introduces several minor fixes and a few new commands from the standard API.

  • tracer() behavior improved to better match the Turtle standard,
  • fixed goto() to support smooth movement (also when not drawing),
  • added methods from the standard API:
    - setworldcoordinates()
    - isdown()
    - setx()
    - sety()
    - teleport()
  • Example files have been included in the archive.
Version 0.93:

Key changes
  • reduced memory usage when filling areas while simultaneously drawing the outline with turtle animation enabled (speed ≠ 0),
  • fixed minor issues related to area-filling precision,
  • fixed issues related to wait (reduced battery consumption),
  • improved rendering of the turtle shape (reduced flickering),
  • set the default fill color to black (previously, an error occurred when attempting to fill an area without specifying a color),
  • added the Screen class (simplified version—see the documentation for details).

Added methods from the standard API:
  • delay
  • deegres
  • radians
  • filling
  • window_width
  • window_height
  • getscreen

Additionally, a simple demo application has been added with a basic example (which can be replaced with any of the included files in the Examples folder).
Version 0.94:
  • fixed bug causing simple straight lines to not render correctly in viewport mode (introduced in v0.93),
  • fixed colormode() to fully match standard Python Turtle API (now properly returns current color mode when called without arguments),
  • fixed circle drawing when using negative extent (previously the turtle would move forward instead of backward, and the turtle shape rotated in the opposite direction),
  • added support for custom grid spacing through Turtle constructor,
  • implemented automatic grid hiding when it becomes too dense after scaling,
  • increased maximum viewport scaling steps to ±7 (previously ±5),
  • added safeguards preventing multiple turtles from using/assigning the same buffer,
  • added safeguards against creating Screen object before any Turtle has been instantiated,
  • added aliases bye() and exitonclick() for done().
TinyTurtle v1.00 is out!🐢

And this one is not just another update.

In fact, this release is closer to a complete rewrite than a typical version bump. Around 90% of the original code has been replaced, and the codebase has grown to almost three times the number of lines compared to the previous version. The goal wasn’t simply to add features, but to rebuild the internal engine so it could be faster, more precise, and easier to extend in the future.

One of the main priorities during this rewrite was compatibility with the CPython Turtle API. The idea is simple: scripts written for Turtle in regular Python should be easy to port to HP Prime with minimal changes (in most cases it’s enough to change the module name from turtle to tinyturtle).

Another important addition is the procedural API, which was missing before. Functions like fd(), lt(), goto(), circle(), etc. can now be used directly without explicitly creating a Turtle object — just like in standard Python Turtle. This makes quick scripts easier to write and also helps port existing Turtle programs with minimal modifications.

Under the hood, the rendering pipeline has been heavily redesigned. TinyTurtle now uses layered rendering buffers (background, drawing layer, cursor overlay, etc.), which allows the engine to update only the parts of the screen that actually changed. This results in smoother animation and significantly more efficient rendering.

A lot of effort also went into reducing memory usage. Several internal structures were redesigned to avoid unnecessary allocations. For example, the fill engine now stores polygon vertices in a packed fixed-point representation, which reduces memory overhead while still allowing precise rasterization.

In fact, the new engine relies much more heavily on fixed-point arithmetic. Instead of using floating point values everywhere, many critical parts now operate in fixed-point form. This includes things like:
  • polygon fill rendering
  • packed vertex storage
  • screen-space coordinate quantization
  • parts of the rasterization pipeline
  • animation and geometry calculations
This approach improves performance on the HP Prime and also helps keep the rendering stable, deterministic, and accurate.

Text rendering has also been redesigned. The old bitmap font has been replaced with a vector font engine, so text is now rendered using stroke geometry (currently only one built-in vector font is available). This integrates naturally with the drawing pipeline and scales cleanly at different sizes.

The viewport mode has also been improved internally. Rendering inside the viewport now uses Cohen–Sutherland line clipping, which avoids drawing segments that fall outside the visible area. This significantly improves performance when exploring large scenes with pan and zoom.

There’s also a small but very useful new feature: title bar support.
You can now display a title using Screen.title(), which draws a cached title bar at the top of the screen without interfering with the drawing area. The title rendering also supports multi-line text.

The grid system and world coordinates remain the same feature-wise, although a few bugs were fixed along the way. The viewport system itself has also been further optimized, so large scenes render even faster.

So while TinyTurtle v1.00 may not look dramatically different on the surface, internally it’s basically a new engine — faster, more memory-efficient, more precise, and much closer to CPython Turtle behavior.

Hopefully this makes it easier (and more fun) to bring Turtle programs from desktop Python onto the HP Prime 🙂

A detailed list of new features and changes can be found on the last page of the documentation.

As always, feedback and experiments are very welcome!
Version 1.10 introduces a new set of features while maintaining high compatibility with the standard CPython Turtle API.

This version ensures that the vast majority of turtle scripts available online can run on HP Prime without significant modifications. Of course, some differences remain, since HP Prime does not include Tkinter. As a result, certain methods required custom implementations to achieve behavior as close as possible to the standard, despite the absence of Tkinter underneath.

Main additions:

  • All built-in cursor shapes from the standard CPython Turtle API have been added and can be used via shape().
  • All cursor shape scaling and transformation methods have been implemented
  • Added the ability to create custom cursor shapes using register_shape() / addshape()
  • Added the stamp() method
  • Added support for font styles in write(), applied to the built-in vector font
  • Multiple additional performance optimizations improving rendering speed
  • Several fixes enhancing compatibility with the standard CPython Turtle API

The full list of changes can be found on the last page of the documentation.

Below are a few examples demonstrating the newly added features.


  • All built-in cursor shapes:


  • Cursor shape scaling and transformation:


  • Custom cursor shapes and stamp():

    Here is an example script that registers a custom shape (a star) and then stamps it along the circumference of a circle. Finally, it is enlarged and stamped once more in the center.

    Code:
    from tinyturtle import *

    star_points = (
        (0.00, 10.00), (2.59, 3.56), (9.51, 3.09), (4.18, -1.36), (5.88, -8.09),
        (0.00, -4.40), (-5.88, -8.09), (-4.18, -1.36), (-9.51, 3.09), (-2.59, 3.56)
    )

    t = Turtle(visible=False)

    s = t.getscreen()
    s.register_shape("star", star_points)

    t.shape("star")
    t.tilt(90)

    t.teleport(0,-100)
    t.showturtle()
    t.speed(2)

    t.pencolor('darkgray')

    t.circle(100)
    t.penup()
    t.goto(0,-80)
    t.color('black','red')

    for i in range (10):
        t.circle(80,36)
        t.stamp()

    t.home()
    t.shapesize(2,2,3)
    t.fillcolor('blue')
    t.stamp()

    done()


    Result:


  • Font styles:
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement