Petri nets, with rules in Hazel

Hazel activities › automata · source on GitHub · hazeljs on npm · how it works

The page keeps the net and draws it; a Hazel program decides what each event does. Click a transition to fire it, or step at random. The rules below are in Hazel's own editor: change them, and the page builds them again with hazeljs. While they have an error or a hole, the page's own JavaScript answers instead, and the log says which did.

⏳ The net is drawn from its definition in Hazel (the module Main, with the rules), once hazeljs has built it.

This app needs JavaScript, and a page served over http (python3 -m http.server, then localhost): Hazel's editor frames take no file:// page.

🪵 event log

The vocabulary, the preamble every module sees (rules/preamble.hz). Each listing is Hazel's editor: Ctrl+click a name, or F12 on it, to go to its definition.

loading rules/preamble.hz…
Common helpers the rules use (rules/Common.hz)
loading rules/Common.hz…
Rules the handler, on_event (rules/Rules.hz)
loading rules/Rules.hz…
Main the net, where it is drawn, and the handler the page calls (rules/Main.hz). The program ends by reading them: (places = Main.places, place_at = Main.place_at, transitions = Main.transitions, transition_at = Main.transition_at, marking = Main.marking, on_event = Main.on_event). Change the net here and the page draws it again.
loading rules/Main.hz…

hazeljs-examples · versions (to 0.0.10, as hazeljs-petri-example) · Apache 2.0 (code), CC BY 4.0 (words) · by Matthew Hammer · an example for hazeljs, after Messed Up Dress Up, the first app with rules in Hazel