Important
π§ This documentation is still under construction. Parts of the node are still under development. There may therefore be minor differences between the node itself and the documentation for the node. The documentation is also not yet complete.
Turtle Graphics has some interesting features. This node makes use of these capabilities. The aim is to show how beautiful graphics can be created with Turtle Graphics.
It will explained later how Turtle Graphics works. It has to be noted that Turtle Graphics makes use of the Python package Tkinter. In variations of this nodes one can think about different cases where Turtle Graphics or/and Tkinter can be used.
As part of the development I could show that it is not necessary to save and load a Turtle Graphics for the later use. A canvas created by Turtle Graphics can be streamed so it can be used as Pil image.
The background of a Turtle Graphics image is by default white. This is completely independent from the background of the screen where the graphics is drawn. By use of Numpy this white background can be removed with a background of personal choice.
If the background is exchanged by a black background it is also possible to remove this background and make the background transparent.
Step by step some more demos to the existing ones will be added. The settings will result in a broader range of graphics creations.
This node is intended for demonstration purposes, but you can use this node for some interesting things. One example is the creation of colourful QR codes.
Over the years I have been working with Turtle Graphics again and again with longer breaks in between. When working on masks for ComfyUI, the fastest way to create N-gons was to use Turtle Graphics. So I started working with Turtle Graphics again.
One goal is to use the node as Turtle Graphics demonstrator and to play with settings of a special demo.
Another goal is it to provide graphics to other applications. One exaample will be given later.
Turtle Graphics was developed in the 60s of the last century for learning and demonstration puposes. Turtle Graphics is an implementation of the popular geometric drawing tools introduced first in the programming language Logo developed 1967. In computer graphics, Turtle Graphics are a special kind of vector graphics using a relative cursor, which is called turtle upon a Cartesian co-ordinate system plane with x and y axis. The turtle itself has three attributes, which are the location, the orientation (or direction) and the pen. The pen has attributes too, which are color, width, and down and up state.
Implementations of Turtle Graphics in programming languages can be found in:
- Logo
- Python
- Scratch
- Java
- JavaScript
- HTML5 Canvas
- C++
- Joy
In this node I made use of the special character of the Python module Turtle Graphics. As long one waits until the image is drawn everything is fine. If not it could be that the code will have a short confusion in form of a catched error in the background.
Turtle Graphics is using Tkinter for the windows management. Starting a draw command Turtle Graphics is opening a (tkinter) window for drawing. Within the node one can decide to show this window or not.
One can decide to let a turtle or another shape drawing the image. This can also be set in the node.
The node settings are largely self-explanatory. Accordingly, I am currently only providing a few comments.
Figure 1 shows a preview of the Turtle Graphics Circles Demo Node.
Figure 1: Turtle Graphics Circles Demo node
Graphic specific settings are:
- circle_radius
- number_rotations
- rotation_angle
- start_angle
Following pseudo code describes the movement of the turtle (in a loop) on the screen.
number_rotations = 36 circle_radius = 100 increment_angle = 10Β° LOOP FOR i FROM 0 TO number_rotations STEP 1 DRAW CIRCLE (circle_radius) ROTATE TURTLE RIGHT (increment_angle) END LOOP
The following (colorful) image was created using the pseudo code settings.
Figure 2: Image created using the pseudo code settings
Following images are drawn with the Turtle Graphics Circles demo node.
π | Column 1 | Column 2 | Column 3 |
---|---|---|---|
Row 1 | ![]() |
![]() |
![]() |
Row 2 | ![]() |
![]() |
![]() |
Row 3 | ![]() |
![]() |
![]() |
Figure 1 shows a preview of the Turtle Graphics Circles Demo Node.
Figure 3: Turtle Graphics Squares Demo
Graphic specific settings are:
to do ..
Following pseudo code describes the movement of the turtle on the screen.
angle = 0Β° increment_angle = 15Β° length = 10 increment_length = 2 number_rotations = 80 LOOP FOR i FROM 1 TO number_rotations STEP 1 LOOP FOR j FROM 1 TO 4 STEP 1 MOVE TURTLE FORWARD (length) ROTATE TURTLE LEFT (90Β°) END LOOP ROTATE TURTLE LEFT (angle) angle = angle + increment_angle length = length + increment_length END LOOP
The following (colorful) image was created using the pseudo code settings.
Figure 4: Image created using the pseudo code settings
Graphic specific settings are:
to do ..
π | Column 1 | Column 2 | Column 3 |
---|---|---|---|
Row 1 | ![]() |
![]() |
![]() |
Row 2 | ![]() |
![]() |
![]() |
Row 3 | ![]() |
![]() |
![]() |
Figure 5: Turtle Graphics Spiral Demo
π | Column 1 | Column 2 | Column 3 |
---|---|---|---|
Row 1 | ![]() |
![]() |
![]() |
Row 2 | ![]() |
![]() |
![]() |
Row 3 | ![]() |
![]() |
![]() |
Following pseudo code describes the movement of the turtle on the screen.
angle = 45Β° max_length = 180 LOOP FOR i FROM 1 TO max_length STEP 1 MOVE TURTLE FORWARD (i) ROTATE TURTLE LEFT (angle) END LOOP
The following (colorful) image was created using the pseudo code settings.
Figure 1 shows the Turtle Graphics Circle Lobes Demo node. The settings for the graphics are fully parameterised.
Figure 6: Turtle Graphics Circle Lobes Demo
Graphic specific settings are:
to do ..
to do ...
π | Column 1 | Column 2 | Column 3 |
---|---|---|---|
Row 1 | ![]() |
![]() |
![]() |
Row 2 | ![]() |
![]() |
![]() |
Row 3 | ![]() |
![]() |
![]() |
Figure 7: Turtle Graphics Concate Lines Demo
Graphic specific settings are:
Following pseudo code describes the movement of the turtle on the screen.
number_rotations = 300 angle = 75Β° LOOP FOR i FROM 1 TO number_rotations STEP 1 MOVE TURTLE FORWARD (i) ROTATE TURTLE RIGHT (angle) END LOOP
The following (colorful) image was created using the pseudo code settings.
π | Column 1 | Column 2 | Column 3 |
---|---|---|---|
Row 1 | ![]() |
![]() |
![]() |
Row 2 | ![]() |
![]() |
![]() |
Row 3 | ![]() |
![]() |
![]() |
Please note that this is a example, which might not be working. Creating such colorful and working QR Codes need some fine tuning. The Difference in contrast between forground color and background color must be 20 % in difference. One needs for compositing an image which fulfills this. This can be reached by try and error. If a QR code scanner is reading the created image it works, otherwise not.
π | Turtle Graphics | QR Code | AI Image |
---|---|---|---|
Images | ![]() |
![]() |
![]() |
Tkinker crashes under unknown circumstances. In general this can be resolved by restarting ComfyUI.
Sometimes following error occures, when closing to often a Turtle Graphics windows while Turtle Graphics is still drawing.
RuntimeError: main thread is not in main loop Tcl_AsyncDelete: async handler deleted by the wrong thread
In general this can be resolved by restarting ComfyUI.
In real-life use of the node, a few questions have arisen that require clarification. As long as I am using a square format the resulting image is with or without upscaling in his quality good. I used a landscape format and the image became blurry. It became even more blurred by changing the background.
Opening and closing of a Turtle Graphics window or start and stop of a Turtle Graphics object is not working as expected.
I need nodes where I can move the starting point of the Turtle Graphics from the center of the drawing area by offset values for x and y.
[1] https://docs.python.org/3/library/turtle.html
If you like what I present here, or if it helps you, or if it is useful, you are welcome to donate a small contribution. Or as you might say: Every TRON counts! Many thanks in advance! π
TQamF8Q3z63sVFWiXgn2pzpWyhkQJhRtW7
DMh7EXf7XbibFFsqaAetdQQ77Zb5TVCXiX
12JsKesep3yuDpmrcXCxXu7EQJkRaAvsc5
0x31042e2F3AE241093e0387b41C6910B11d94f7ec