Skip to main content

Hardware-accelerated DOM-based UI & 2D Game Engine

Project description

Doodle Engine ๐ŸŽจ๐Ÿš€

Hardware-Accelerated Hybrid C-Python UI & 2D Game Engine

Doodle is a high-performance, lightweight UI and 2D game engine combining a native C rendering core (powered by Raylib) with a highly reactive Python scripting layer.

By bypassing heavy browser runtimes (like Chromium/Electron), Doodle parses dynamic HTML-like templates and CSS stylesheets in a single pass directly to GPU-accelerated graphics, procedural audio synths, and collision meshes.


๐Ÿ“‚ Repository Organization

Doodle/
โ”œโ”€โ”€ docs/                   # Full reference specifications & requirements
โ”‚   โ”œโ”€โ”€ cheatsheet.md       # API & layout syntax quick reference
โ”‚   โ”œโ”€โ”€ requirements.md     # Engine specifications and architecture blueprint
โ”‚   โ””โ”€โ”€ unused_reference.md  # Unused HTML/CSS/C engine features reference
โ”œโ”€โ”€ doodle/                 # Python package wrapper
โ”‚   โ”œโ”€โ”€ __init__.py         # Tween animations, reactive state binding, event emitter
โ”‚   โ””โ”€โ”€ cli.py              # PyInstaller packager cli
โ”œโ”€โ”€ examples/               # Game demonstrations
โ”‚   โ””โ”€โ”€ breakout/           # Breakout game demo
โ”‚       โ”œโ”€โ”€ layout.html     # Game view DOM nodes & inline handlers
โ”‚       โ”œโ”€โ”€ styles.css      # Retro arcade UI styles, flexbox, and crt shaders
โ”‚       โ”œโ”€โ”€ shaders/        # Custom GLSL Fragment shaders
โ”‚       โ””โ”€โ”€ main.py         # Collision, input, and game state script
โ”œโ”€โ”€ src/                    # C-Extension Core (complies to _doodle.pyd)
โ”‚   โ”œโ”€โ”€ setup.py            # Setuptools compilation script
โ”‚   โ”œโ”€โ”€ expose_raylib.c     # Python-to-C bindings, Raylib window, and particle pool
โ”‚   โ”œโ”€โ”€ mparser.h / .c      # n-ary DOM parser, CSS registry handler, and layout box solver
โ”‚   โ”œโ”€โ”€ dutils.h / .c       # Custom color parser, fast unit converter, and math helpers
โ”‚   โ””โ”€โ”€ daudio.h / .c       # Polyphonic synth, multi-voice ADSR envelope generator
โ”œโ”€โ”€ third_party/            # Static Raylib binaries & dependencies
โ””โ”€โ”€ README.md               # You are here!

๐Ÿ› ๏ธ Getting Started & Compilation

1. Requirements

  • OS: Windows (x64) / linux
  • Python: Python 3.11+ (with virtual environment capability)
  • C Toolchain: MSYS2/MinGW-w64 (C:\msys64\ucrt64\bin for gcc and compilation libraries) / linux cc compiler

2. Quick Setup & Build

From the repository root directory, run the setuptools compilation with your virtual environment's python. Specify the compiler:

# Add GCC to PATH (if not global)
$env:PATH = "C:\msys64\ucrt64\bin;" + $env:PATH

# Compile the native C extension
cd src
..\.venv\Scripts\python.exe setup.py build_ext --inplace -c mingw32

# Copy the compiled pyd module to the doodle library
cd ..
Copy-Item -Path "src\_doodle.cp311-win_amd64.pyd" -Destination "doodle\_doodle.pyd" -Force

3. Run the Breakout Demo

Launch the breakout game:

cd examples/breakout
..\..\.venv\Scripts\python.exe main.py

๐Ÿ—๏ธ XML Markup (layout.html) & CSS (styles.css)

Doodle supports layout-driven layouts with traditional tag structures and inline event bindings.

Core Elements

  • <view>: Structural container. Standard flex container or a 2D camera boundary using <view camera="true">.
  • <text>: Text layout with reactive state-bound variables like SCORE: {{ score }}.
  • <image>: Renders cached bitmaps using src="...".
  • <button>: Clickable target with mouse state callbacks.
  • <circle>: Renders shapes using radius and color parameters.
  • <line>: Renders vectors using x2, y2, thickness, and color.

Event Hooks

Directly attach Python functions inline:

  • onclick="python_function_name"
  • onhover="python_function_name"

Layout Styles

  • Sizing Rules: width / height support pixels (100px), percentages (50%), growth parameters (grow), and content sizing (fit).
  • Flexbox Attributes: display: flex, flex-direction (row | column), justify-content (center | space-between | space-around), align-items.
  • Cosmetics: background-color, border-radius, border-color, border-width, opacity, font-family, font-size.
  • Juice Shaders: Add custom GLSL fragment shaders directly to views using shader-path: "shaders/crt.fs".

๐Ÿ Python OOP APIs

Initialization

import doodle

# Game state passed for template rendering
state = {"score": 0, "lives": 3}

doodle.run(
    layout="layout.html",
    style="styles.css",
    width=800,
    height=600,
    title="Game Window",
    state=state
)

Node Manipulation

# Fetch reference
paddle = doodle.get_node("paddle")

# Read/Write positions
paddle.position = (350, 500)
paddle.x += 10.0

# Easing animations
doodle.animate("paddle", target_x=350, target_y=500, duration=0.4, ease="quad_out")

Input Polling

# Keys
doodle.is_key_down(263)      # Left arrow key code
doodle.is_key_pressed(82)    # R key code

# Mouse
mx = doodle.get_mouse_x()
doodle.set_mouse_cursor(4)   # Changes mouse pointer style

๐Ÿ”Š Polyphonic Procedural Sound Synthesizer

Doodle includes an integrated multi-voice synthesizer utilizing ADSR Envelopes to play retro sound waves without lagging the update tick loop.

# Play procedural tone
doodle.play_synth(
    freq=440.0,
    duration=0.15,
    wave_type=doodle.WAVE_TRIANGLE,
    attack=0.01,
    decay=0.05,
    sustain=0.3,
    release=0.05
)

Wave Types: WAVE_SINE (0), WAVE_SQUARE (1), WAVE_TRIANGLE (2), WAVE_SAWTOOTH (3), WAVE_NOISE (4)


โšก Performance Optimizations

Doodle is engineered for maximum performance, featuring multiple custom optimizations:

  1. Single-Item DOM Lookup Cache: Node lookup (FindNodeById) caches the pointer of the last requested node. Repetitive state checks (like checking click and hover events in the same frame) resolve in $O(1)$ without scanning the DOM tree.
  2. Precompiled Format Templating: Template variables {{ score }} are compiled once into native Python {score} string format structures, converting reactive updates from regex replacements to C-speed string builders.
  3. Loop Division Elimination: Particle shaders and polyphonic audio generators use cached precalculated inverse values (inv_max_lifetime and phase_increment) to replace expensive division operations with single-clock multiplication instructions.
  4. Square Wave Optimization: Square waves skip standard trignometric sinf calculations, computing high-low status directly from phase boundaries.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

doodle_ui-0.1.0-cp311-cp311-win_amd64.whl (577.6 kB view details)

Uploaded CPython 3.11Windows x86-64

doodle_ui-0.1.0-cp311-cp311-musllinux_1_2_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

doodle_ui-0.1.0-cp311-cp311-musllinux_1_2_i686.whl (1.8 MB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ i686

doodle_ui-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (909.9 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

doodle_ui-0.1.0-cp311-cp311-macosx_11_0_arm64.whl (657.8 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

File details

Details for the file doodle_ui-0.1.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: doodle_ui-0.1.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 577.6 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for doodle_ui-0.1.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 aeff1da8ccfe7a86aa5bc42f9dacc729717320e293d792deea7f2f2c442e77c6
MD5 7cd8525bca38043f63db27f65f9736b6
BLAKE2b-256 99cf7ae93796cd303ab29389d29345fa2cb62c7621d937a62079236f3ffcc635

See more details on using hashes here.

File details

Details for the file doodle_ui-0.1.0-cp311-cp311-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for doodle_ui-0.1.0-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 7ec4b6dee6bf9eb175e548bee1211fd61cad6938d056368ea92db961e3f00914
MD5 e7fba81905daa80c777c1e6a1c7ba23a
BLAKE2b-256 43f640d82706d253a7ab2b7287712ebc984209819cf178987f028dc01dfa29a4

See more details on using hashes here.

Provenance

The following attestation bundles were made for doodle_ui-0.1.0-cp311-cp311-musllinux_1_2_x86_64.whl:

Publisher: release.yml on DUDDLEGOD/Doodle

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file doodle_ui-0.1.0-cp311-cp311-musllinux_1_2_i686.whl.

File metadata

File hashes

Hashes for doodle_ui-0.1.0-cp311-cp311-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 50155cb4bff71c9df776d5da25d67d056a39073b3102954799530f5a76626263
MD5 a645e6f4eba51cbe00e484de3460061f
BLAKE2b-256 fd2105d2b3869e72d8695118c0681988c8f6848927f19171eda799ecef1caca9

See more details on using hashes here.

Provenance

The following attestation bundles were made for doodle_ui-0.1.0-cp311-cp311-musllinux_1_2_i686.whl:

Publisher: release.yml on DUDDLEGOD/Doodle

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file doodle_ui-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for doodle_ui-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 06fea729230f8ff60f9677a99c469252f86c393e758656dcd167ce201fe47054
MD5 39a540c1a7ab400d8a62a4a8474a5525
BLAKE2b-256 4fb9e345e10719d359cacd38cefb57393e1a507a5d45aab4aa0319f0e4545eb7

See more details on using hashes here.

Provenance

The following attestation bundles were made for doodle_ui-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on DUDDLEGOD/Doodle

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file doodle_ui-0.1.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for doodle_ui-0.1.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9a36741c1e329a3d838baf8415786fe565ac863767fe56e085792a0d2d933a96
MD5 4223126ccb0b392f03c3a42306ef3398
BLAKE2b-256 c8325aff43752d3fd0e13fedcbd65edbfa4eb727a150599f93be2a96d3b7b0ee

See more details on using hashes here.

Provenance

The following attestation bundles were made for doodle_ui-0.1.0-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: release.yml on DUDDLEGOD/Doodle

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page