Golden Gate

May 16, 2018 Logic gate playground and my WWDC18 scholarship submission.

Just like the year before, Apple offered a WWDC ticket to students, who submitted outstanding visually interactive Swift Playgrounds.

In this post, I’d like to show what I’ve created for my submission: A logic gate simulator in the WWDC18 theme that features several puzzles as well as a sandbox and some advanced creations.

You can play around with the source code on GitHub!

Screenshot of Golden Gate

Screenshot: Introduction to Digital Circuits

At its core, my Swift Playground Book comprises a logic simulator with accompanying puzzles and explanations as well as a solution checker, which doesn’t look for specific components but rather simulates the learner’s circuit and asserts expected outputs for various input states. Thus, it is possible to check progress without discouraging alternative solutions.

The simulator itself is dynamic in a way that lets it update passive components while being modified, which makes for instant visual feedback. Active components update their outputs at a fixed rate and also simulate propagation delay. In other words, my logic simulator also supports feedback loops that enable flip-flops or clocks.

Screenshot of Golden Gate

Screenshot: RS-Flip-Flop

It is built on top of lightweight Swift structs and heavily uses language features such as protocol extensions and synthesized protocol conformance. Thus, it was a breeze to implement Codable support for loading and saving levels as JSON.

This is why I also developed a document-based macOS sandbox application with AppKit for content creation. It was very easy to reuse code on both macOS and iOS since I’ve employed SceneKit to visualize the logic simulation.

Even though I’ve never touched SceneKit before, it was a great learning experience getting started. I created my textures and images in Sketch and geometries in Blender. Another integral part to my process was—of course—the Xcode Scene Editor.

Adding and moving circuit components on iOS couldn’t be easier—thanks to iOS 11’s new drag’n’drop API. Triggering and removing components is based on gesture recognizers.

Thanks for your interest!

If you like my content, I would be honored if you gave my website a star on GitHub!