Lugforth

Examples

The examples are in folders by kind (SDL2 words, see docs/SDL2.md):

folder what
games/ sdl2_breakout.fs, sdl2_roguelike.fs (with its tile sheet), sdl2_2048.fs (and the terminal 2048.fs), three games after r3forth (below: sdl2_tetris.fs, sdl2_snake.fs, sdl2_minesweeper.fs), sdl2_mastermind.fs, sdl2_raycaster.fs (a Doom-like maze by raycasting, steered with the mouse), heart_game.fs, pinball/pinball.fs; games_tests.fs, raycaster_tests.fs and 2048_tests.fs are their tests
graphics/ sdl2_demo.fs, sdl2_3d.fs (turning wireframe cube, pyramid and octahedron; 3d.fs is the math), sdl2_turtle.fs (Logo turtle graphics, words of forthtoise from Forth is Fun, English and French), boxes.fs, heart_graph.fs, min_grf.fs, bezier_test.fs
music/ sdl2_drums.fs, sdl2_pianoroll.fs, fm/sdl2_fm.fs (FM synthesizer with MIDI input, also in the browser; see music/fm/README.md)
utils/ txt2tags.fs, logs.fs, into.fs, complex.fs, infix/, inference/ (rules engine), gemini/ (arrays, JSON)
system/ networking (curl.fs, udp.fs, httpd_sample.fs, espnow.fs), assemblers (asm_xtensa.fs, code_x64.fs, code_xtensa.fs), varvara/ (Uxn virtual machine)
bench/ the benchmarks below, speed.fs
web/ HTML pages that load the web build

The Turtle: the window shows the drawing, you type lines in the terminal (100 forward 90 right, loops allowed), then go draws at once, speed 100 and play draw stroke by stroke, list, undo, new, demo, help. Run one with lugforth examples/games/sdl2_breakout.fs, or include games/sdl2_breakout.fs from the examples folder. On the bare-metal boards the folders are kept on the disk or the stick (include games/sdl2_snake.fs, include system/varvara/varvara_rpi.fs), and the website (ports/web/BUILD) copies the files that run in the browser by name.

In the browser

Several examples also run in the browser, from the website, with the very same files:

Benchmarks: lugforth vs C vs uxn

Two benchmarks, each in three files doing the same work (same algorithm, constants and data): bench_sieve and bench_lines, as .fs, .c and .tal (uxn assembly). make bench builds and runs all six; make help lists the targets. The ratios matter, the times depend on the machine.

benchmark what it measures C uxn lugforth
bench_sieve sieve up to 32768, 200 runs, no I/O 0.078 ms 7.1 ms 7.8 ms
bench_lines 100 Bresenham lines per frame through the real display path 0.43 ms 3.7 ms 3.0 ms

Pure interpretation is about 100 times slower than C for tight integer loops, for lugforth and uxn alike. With real work behind a library or device call (the SDL2 renderer, uxn's Screen) the gap shrinks to 7-9 times, which is the case that matters for drawing games.

bench_lines.fs stays open on the last frame (Esc to quit); BENCH_HEADLESS=1 exits at once. make view-lines, view-lines-c and view-lines-uxn open a window to check the drawing by eye.

pinball/

lugforth examples/games/pinball/pinball.fs: a menu (up/down, Enter, or 1 and 2; Esc in a game comes back to it) with two tables. common.fs holds what they share (fixed point helpers, 3x5 font, seven segment digits).

varvara/

A Uxn/Varvara virtual machine in Forth: lugforth examples/system/varvara/uxncli.fs program.rom runs a ROM in the terminal. See varvara/README.md.

txt2tags.fs

A converter from basic txt2tags syntax to HTML, written in Forth:

lugforth examples/utils/txt2tags.fs examples/utils/txt2tags_demo.t2t > demo.html

or include examples/utils/txt2tags.fs then s" doc.t2t" t2t-file. The header comment lists the supported syntax.

Games after r3forth

r3forth by Pablo Reda (MIT license) is a Forth of the ColorForth family with its own syntax (:word, #var, conditionals followed by ( ) blocks, fixed point numbers), so its games are not loaded as they are but written again in lugforth, keeping their ideas. Only libSDL2 is needed: no font or image files, the digits come from a 3x5 bitmap. They also run on the bare-metal boards (ports/rpi, ports/efi: include sdl2_tetris.fs from the card or the stick).

Beside them, written for lugforth:

games_tests.fs tests the logic of the four without opening a window (make test-ports).

Ports from eForth Windows

eForth Windows by Marc Petremann is a ueForth for Windows, so its code loads in lugforth almost as is (value/to, { } locals, vocabulary, :noname, floating point). Three of its projects are here; they are GPL (derived from his code), unlike the rest of the repository. Each file says what is his and what is new.

make test-ports runs 2048_tests.fs, 3d_tests.fs, inference/inference_tests.fs, inference/lamp_diagnosis_tests.fs and games_tests.fs.