Skip to content

zentrocdot/ComfyUI-Turtle_Graphics_Demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

ComfyUI Turtle Graphics Demo

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.

Get Started

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.

Introduction

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.

Main Goals of the Node

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

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.

Turtle Graphics Implementations

Implementations of Turtle Graphics in programming languages can be found in:

  • Logo
  • Python
  • Scratch
  • Java
  • JavaScript
  • HTML5 Canvas
  • C++
  • Joy

Turtle Graphics and Python

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.

Node Settings

The node settings are largely self-explanatory. Accordingly, I am currently only providing a few comments.

Turtle Graphics Circles Demo Node

Node Preview

Figure 1 shows a preview of the Turtle Graphics Circles Demo Node.

image

Figure 1: Turtle Graphics Circles Demo node

Graphic specific settings are:

  • circle_radius
  • number_rotations
  • rotation_angle
  • start_angle

Pseudo Code

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.

ComfyUI_00622_

Figure 2: Image created using the pseudo code settings

Graphics Examples

Following images are drawn with the Turtle Graphics Circles demo node.

πŸ“Ž Column 1 Column 2 Column 3
Row 1 ComfyUI_00625_ ComfyUI_temp_otckr_00032_ ComfyUI_temp_otckr_00034_
Row 2 ComfyUI_00567_ ComfyUI_00568_ ComfyUI_00572_
Row 3 ComfyUI_00577_ ComfyUI_00579_ ComfyUI_00593_

Turtle Graphics Squares Demo

Node Preview

Figure 1 shows a preview of the Turtle Graphics Circles Demo Node.

image

Figure 3: Turtle Graphics Squares Demo

Graphic specific settings are:

to do ..

Pseudo Code

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.

image

Figure 4: Image created using the pseudo code settings

Graphic specific settings are:

to do ..

Graphics Examples

πŸ“Ž Column 1 Column 2 Column 3
Row 1 ComfyUI_temp_otckr_00021_ ComfyUI_temp_otckr_00004_ (4) ComfyUI_temp_otckr_00005_ (8)
Row 2 ComfyUI_temp_otckr_00009_ (2) ComfyUI_temp_otckr_00029_ ComfyUI_temp_otckr_00040_
Row 3 ComfyUI_temp_otckr_00011_ (4) ComfyUI_temp_otckr_00022_ ComfyUI_temp_otckr_00026_

Turtle Graphics Spiral Demo Node

Node Preview

image

Figure 5: Turtle Graphics Spiral Demo

πŸ“Ž Column 1 Column 2 Column 3
Row 1 ComfyUI_temp_otckr_00002_ (4) ComfyUI_temp_otckr_00008_ (2) ComfyUI_temp_otckr_00021_ (1)
Row 2 ComfyUI_temp_otckr_00027_ ComfyUI_temp_otckr_00005_ (10) ComfyUI_temp_otckr_00028_
Row 3 ComfyUI_00609_ ComfyUI_00605_ ComfyUI_00621_

Pseudo Code

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.

image

Turtle Graphics Circle Lobes Demo Node

Node Preview

Figure 1 shows the Turtle Graphics Circle Lobes Demo node. The settings for the graphics are fully parameterised.

image

Figure 6: Turtle Graphics Circle Lobes Demo

Graphic specific settings are:

to do ..

Pseudo Code

to do ...

Graphics Examples

πŸ“Ž Column 1 Column 2 Column 3
Row 1 ComfyUI_temp_otckr_00005_ (7) ComfyUI_temp_otckr_00006_ (2) ComfyUI_temp_otckr_00010_ (4)
Row 2 ComfyUI_temp_otckr_00013_ ComfyUI_temp_otckr_00015_ (1) ComfyUI_temp_otckr_00016_
Row 3 ComfyUI_temp_tvbxm_00010_ (1) ComfyUI_temp_tvbxm_00013_ ComfyUI_temp_tvbxm_00016_

Turtle Graphics Concate Lines Demo Node

Node Preview

image

Figure 7: Turtle Graphics Concate Lines Demo

Graphic specific settings are:

Pseudo Code

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.

image

Graphics Examples

πŸ“Ž Column 1 Column 2 Column 3
Row 1 ComfyUI_00532_ ComfyUI_00533_ ComfyUI_00535_
Row 2 ComfyUI_00536_ ComfyUI_00540_ ComfyUI_00545_
Row 3 ComfyUI_00556_ ComfyUI_00557_ ComfyUI_00561_

Real Life Example

Workflow Preview

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.

image

Example Images

πŸ“Ž Turtle Graphics QR Code AI Image
Images ComfyUI_temp_voxnf_00024_ (1) ComfyUI_temp_mzxdj_00009_ image

Known Problems

Tkinter Crash

Tkinker crashes under unknown circumstances. In general this can be resolved by restarting ComfyUI.

ComfyUI Crash

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.

Open Questions

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.

Open Issues

Opening and closing of a Turtle Graphics window or start and stop of a Turtle Graphics object is not working as expected.

To-Do

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.

References

[1] https://docs.python.org/3/library/turtle.html


Donation

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! πŸ˜ƒ

${\textnormal{\color{navy}Tron}}$

TQamF8Q3z63sVFWiXgn2pzpWyhkQJhRtW7

${\textnormal{\color{navy}Doge}}$

DMh7EXf7XbibFFsqaAetdQQ77Zb5TVCXiX

${\textnormal{\color{navy}Bitcoin}}$

12JsKesep3yuDpmrcXCxXu7EQJkRaAvsc5

${\textnormal{\color{navy}Ethereum}}$

0x31042e2F3AE241093e0387b41C6910B11d94f7ec

About

ComfyUI-Turtle_Graphics_Demos

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

Packages

No packages published

Languages