Super Toroid using RayLib ~ Twisted Doughnut

91 views
Skip to first unread message

Bert Mariani

unread,
May 22, 2026, 4:52:09 PM (13 days ago) May 22
to The Ring Programming Language
Hello Mahmoud it ALL

Attached:
     SuperToroid.ring

Draws a Super Toroid using RayLib
Which looks like a Twisted Doughnut.
See captures below.

Snap1.png

twisted-doughnut.png


supertoroid.ring

Mahmoud Fayed

unread,
May 22, 2026, 8:09:15 PM (13 days ago) May 22
to The Ring Programming Language
Hello Bert

Thanks for sharing :D
I tried it, it's very nice but works at 10 FPS on my machine

Attached an updated version that works at 81 FPS on my machine (i.e. 8x faster)

The idea behind optimization (Instead of creating the vectors as objects each time inside the nested loops, just create it one time before the loop)

shot.png


Greetings,
Mahmoud
supertoroid_optimized.ring

Bert Mariani

unread,
May 23, 2026, 12:43:21 PM (12 days ago) May 23
to The Ring Programming Language
Thanks for the update Mahmoud !!

I am now getting upt op 40 FPS on my computer.
Definitely faster and smoother than before

Regards
Bert Mariani

The Future of Programming

unread,
May 23, 2026, 1:11:34 PM (12 days ago) May 23
to The Ring Programming Language
Hello Bert

You are welcome :D

Greetings, 
Mahmoud

--

---
You received this message because you are subscribed to the Google Groups "The Ring Programming Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ring-lang+...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/ring-lang/7a1f2be5-f82e-4ffa-bc5f-e58cb628afdfn%40googlegroups.com.

Azzeddine Remmal

unread,
May 23, 2026, 8:08:30 PM (12 days ago) May 23
to The Ring Programming Language
Hello Bert  Mahmoud 


 1. 3D Vertex Rotation Optimization:
    - Redundant vertex rotations were eliminated. Instead of rotating shared vertices multiple times per face
      inside the drawing loop (approx. 10,800 transformations/frame), all vertices are rotated exactly once
      per frame in a dedicated linear loop (only 3,721 transformations/frame). This achieved a ~65% reduction
      in complex 3D trigonometric transformations.

 2. Vector3 Pre-allocation (Memory & Garbage Collection Optimization):
    - Replaced the continuous creation and mutation of temporary managed Vector3 objects inside the deep loop.
      A fixed array of 3,721 Vector3 objects is pre-allocated once at startup and reused, saving more than
      32,000 C API structure modification calls and massive interpreter garbage-collection overhead per frame.

 3. Pre-cached Colors (Logic Optimization):
    - The segment coloring calculation (floor(j * 6 / STP) and its 6 'if/else' checks) was fully pre-computed
      at startup into a 'colors' lookup list. The drawing loop now retrieves colors via a simple O(1) list
      lookup (colors[j+1]), removing thousands of float math operations and branching checks per frame.

 4. Ultra-tight Inner Drawing Loop (Reduced Variable & Index Overhead):
    - Eliminated index multiplications (i * N1) from the inner drawing loop.
    - Substituted manual additions for vertex lookups with sequential pointer-like increments (idx1 = idx1 + 1).
    - Removed all temporary local variable allocations (such as idx3, col, v2, v3) inside the inner loop,
      avoiding over 14,000 variable declaration/garbage-collection overhead cycles per frame.

Greetings,
Azzeddine
supertoroid_optimized.ring

Mahmoud Fayed

unread,
May 23, 2026, 9:05:16 PM (12 days ago) May 23
to The Ring Programming Language
Hello Azzeddine

Thanks for sharing :D

The updated version now works at 117 FPS on my machine

shot.png

Greetings,
Mahmoud

Bert Mariani

unread,
May 23, 2026, 10:53:35 PM (12 days ago) May 23
to The Ring Programming Language
Hello Azzeddine

Great Improvements !!
I now get ~ 85 FPS on my machine
And the lines look sharper.

Snap2.png

Reply all
Reply to author
Forward
0 new messages